教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 如何用shell脚本分析网站日志统计PV、404、500等数据

如何用shell脚本分析网站日志统计PV、404、500等数据

发布时间:2014-12-24   编辑:jiaochengji.com
本文介绍了使用shell脚本分析网站日志统计PV(浏览量)、404、500等数据的方法,学习下shell脚本做数据分析的方法,有需要的朋友做个参考。

以下shell脚本能统计出网站的总访问量,以及404,500出现的次数。
统计出来后,可以结合监控宝来进行记录,进而可以看出网站访问量是否异常,是否存在攻击。
还可以根据查看500出现的次数,进而判断网站程序是否出现异常。

完整脚本代码:
 

复制代码 代码示例:

#!/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.jiaochengji.com/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 "<pre>\nc404:${c404}\nc500:${c500}\ntotal:${total}\n</pre>" > /data/www/status/www.jiaochengji.com.html

脚本最后一行是以:
 

复制代码 代码示例:
<pre>
c404:1102
c500:545
total:55463
</pre>

的格式写入到一个www.jiaochengji.com.html文件,再结合监控宝的自定义监控来收集这些信息。
非常的方便,监控宝会自动出图表。

您可能感兴趣的文章:
如何用shell脚本分析网站日志统计PV、404、500等数据
分析日志统计网站pv 404 500状态码的shell脚本
shell统计pv与uv、独立ip的方法
shell脚本实现网站日志分析统计
搜索引擎蜘蛛爬行统计分析
自动统计网站访问日志的shell脚本
看懂IIS日志
分析apache日志中蜘蛛爬行记录数量的shell脚本(图文)
golang url拆分出domain_回顾腾讯面试经历——golang后端开发岗位
404 Not Found代码是什么意思 404错误是什么意思

关键词: linux shell  日志分析   
[关闭]
~ ~