设为首页 收藏本站
查看: 751|回复: 0

[经验分享] nginx日志统计分析

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-3-30 14:43:45 | 显示全部楼层 |阅读模式
本文主要使用的是grep,awk,cut等工具来对nginx日志进行统计和分析,具体如下:

1,列出当天访问最多次数的ip地址
cut -d- -f 1 /usr/local/nginx/logs/20160329/access_2016032913.log |uniq -c | sort -rn | head -20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@httpservera 20160329]# cut -d- -f 1 /usr/local/nginx/logs/20160329/access_2016032913.log |uniq -c | sort -rn | head -20  
     69 180.116.214.31
     45 180.116.214.31
     45 180.116.214.31
     36 49.80.54.111
     35 183.206.185.204
     35 180.116.214.31
     32 49.80.54.111
     32 49.80.54.111
     32 180.116.214.31
     31 117.136.45.101
     29 180.116.214.31
     28 218.205.19.112
     28 180.116.214.31
     28 180.116.214.31
     27 49.80.54.111
     27 222.185.248.242
     24 49.80.54.111
     24 175.0.8.161
     23 49.80.54.111
     23 49.80.54.111




2,查看某一个页面被访问的次数
[iyunv@httpservera 20160329]#grep "/index.php" log_file | wc -l

3,查看每一个IP访问了多少页面并排序
awk '{++S[$1]} END {for (a in S) print a,S[a]}' access_2016032913.log |uniq|sort -rn|more
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[iyunv@httpservera 20160329]# awk '{++S[$1]} END {for (a in S) print a,S[a]}' access_2016032913.log |uniq|sort -rn|more
223.94.229.51 148
223.73.166.191 1
223.68.252.103 156
223.68.167.66 2
223.68.106.138 43
223.67.99.72 7
223.67.153.173 12
223.66.93.152 15
223.66.38.31 103
223.65.191.181 1
223.65.191.135 11
223.65.190.71 13
223.65.141.78 3
223.64.63.71 31
223.64.63.229 7
223.64.62.242 59
223.64.62.23 27
223.64.62.216 1
223.64.62.160 40
223.64.61.136 28
223.64.60.80 13
223.64.60.21 12
223.64.237.37 187
223.64.209.247 2
223.64.158.4 15



其中,sort -rn 按照数字从大到小排序,uniq 将重复行去除。

4,查看某一个ip访问了那些页面:grep ^xx.xx.xx.xx log_file |awk '{print $1,$7}'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@httpservera 20160329]# grep ^223.147.39.194 17 access_2016032913.log |awk '{print $1,$7}'          grep: 17: No such file or directory
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json
access_2016032913.log:223.147.39.194 //thirdpartyapi/appaction/app_action/action_send_batch.json
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //customer/customerInfo/getCustUnReadMsgInfo.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json
access_2016032913.log:223.147.39.194 //remind/redDot/checkRedDot.json



5,去掉搜索引擎统计当天的页面:awk '{print $12,$1}' access_2016032913.log | grep ^\"Mozilla | awk '{print $2}' |sort | uniq | wc -l      
1
2
[iyunv@httpservera 20160329]# awk '{print $12,$1}' access_2016032913.log | grep ^\"Mozilla | awk '{print $2}' |sort | uniq | wc -l      
35




6,查看一个小时内有多少ip访问:
1
2
[iyunv@httpservera 20160329]# awk '{print $4,$1}' access_2016032913.log | grep 29/Mar/2016:13 | awk '{print $2}'| sort | uniq | wc -l   
1926






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-197706-1-1.html 上篇帖子: nginx 限速不生效解决 下篇帖子: Nginx配置文件 统计
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表