您现在的位置是:网站首页> 编程资料编程资料
使用shell脚本分析网站日志统计PV、404、500等数据_linux shell_
2023-05-26
332人已围观
简介 使用shell脚本分析网站日志统计PV、404、500等数据_linux shell_
下面的脚本能统计出网站的总访问量,以及404,500出现的次数。统计出来后,我们可以结合监控宝来进行记录,进而可以看出网站访问量是否异常,是否存在攻击,一目了然。还可以根据查看500出现的次数,进而判断网站程序是否出现异常。
脚本最后一行是以:
的格式写入到一个www.jb51.net html文件,再结合监控宝的自定义监控来收集这些信息。非常的方便,监控宝会自动出图表。
复制代码 代码如下:
#!/bin/bash
#purpose:count nginx or apache or other webserver status code using jiankongbao
#how to:run the script every 5 minutes with crontab
log_path="/var/log/nginx/www.jb51.net/access.log"
becur=`date -d "5 minute ago" +%H%M%S`
code=(`tac $log_path | awk -v a="$becur" -v total=0 -F [' ':] '{
t=$5$6$7
if (t>=a){
code[$12]++
total++
}
else {
exit;
}
}END{
print code[404]?code[404]:0,code[500]?code[500]:0,total
}'
`)
c404=${code[0]}
c500=${code[1]}
total=${code[2]}
echo -e "
#purpose:count nginx or apache or other webserver status code using jiankongbao
#how to:run the script every 5 minutes with crontab
log_path="/var/log/nginx/www.jb51.net/access.log"
becur=`date -d "5 minute ago" +%H%M%S`
code=(`tac $log_path | awk -v a="$becur" -v total=0 -F [' ':] '{
t=$5$6$7
if (t>=a){
code[$12]++
total++
}
else {
exit;
}
}END{
print code[404]?code[404]:0,code[500]?code[500]:0,total
}'
`)
c404=${code[0]}
c500=${code[1]}
total=${code[2]}
echo -e "
\nc404:${c404}\nc500:${c500}\ntotal:${total}\n" > /data/www/status/www.jb51.net.html脚本最后一行是以:
复制代码 代码如下:
c404:1102
c500:545
total:55463
的格式写入到一个www.jb51.net html文件,再结合监控宝的自定义监控来收集这些信息。非常的方便,监控宝会自动出图表。
相关内容
- 使用shell脚本采集系统cpu、内存、磁盘、网络等信息_linux shell_
- Bash Shell字符串操作小结_linux shell_
- bash批量重命名、批量更改后辍的方法_linux shell_
- Shell中处理包含空格的文件名实例_linux shell_
- shell实现FizzBuzzWhizz问题示例(拉勾网面试题)_linux shell_
- vtune自动化安装脚本_linux shell_
- 利用shell删除数据表中指定信息和字段对应的文件_linux shell_
- nginx多server日志分割脚本分享_linux shell_
- 图片批量压缩大小脚本分享_linux shell_
- shell统计pv和uv、独立ip的方法_linux shell_
