温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

accesslog分析案例

发布时间:2020-06-07 22:22:20 来源:网络 阅读:715 作者:zhouanyafu 栏目:软件技术

假设pcaccess.log是某应用的accesslog

a.查看日志中访问次数最多的前10个IP

cat pcaccess.log|cut -d ' ' -f 1 |sort |uniq -c | sort -nr | awk '{print $0 }' | head -n 10 |less

b.查看日志中出现100次以上的IP

#cat pcaccess.log |cut -d ' ' -f 1 |sort |uniq -c | awk '{if ($1 > 100) print $0}'|sort -nr |less


c.查看最近访问量最高的URL

假设第九个位置是url,则命令如下:
#cat pcaccess.log |tail -10000|awk '{print $9}'|sort|uniq -c|sort -nr|less

左边的数字是出现的次数,右边的参数是对应的URL

d.查看最近访问量最高的页面(.jsp)

#cat pcaccess.log |awk '{print $9}'|grep '.jsp'|sort|uniq -c|sort -nr |head -n 10


e.查看日志中访问超过100次的页面

#cat pcaccess.log | cut -d ' ' -f 9| sort |uniq -c | awk '{if ($1 > 100) print $0}' | less


f.某天访问网站的独立IP有多少

#cat pcaccess.log|grep '17/Oct/2012'|grep "******"|wc|awk '{print $1}'|uniq


g.统计某url,一天的访问次数

#cat pcaccess.log |grep '17/Oct/2012'|awk '{print $9}'|grep '/model.html'|wc -l


h.列出传输时间超过 3 秒的文件

首先把请求时间和文件提取出来(假如倒数第四个域是请求时间)

#cat pcaccess.log|awk '{print $9 $(NF-4)}' >timeurl

找出传输时间超过3s的文件

#cat timeurl|awk '($NF > 3){print $1$2}'

找出传输时间超过3s的文件并且出现次数最多的前20
#cat timeurl|awk '($NF > 3){print $1}'|sort -n|uniq -c|sort -nr|head -20

i.列出传输最大的几个exe文件(分析下载站的时候常用)

#cat pcaccess.log |awk '($7~/\.exe/){print $14,$9}'|sort -nr|head -20

j.统计404的连接

#awk '($12 ~/404/)' pcaccess.log | awk '{print $12,$9}' | sort|uniq -c|sort -nr


k.统计http status

#cat  pcaccess.log  |awk '{counts[$(12)]+=1}; END {for(code in counts) print code, counts[code]}'
#cat pcaccess.log |awk '{print $12}'|sort|uniq -c|sort -rn


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI