摘要:
假设日志内容如下,第二列代表响应时间,单位ms:[root@ecs01 logs]# cat test.log http://www.b...
假设日志内容如下,第二列代表响应时间,单位ms:
[root@ecs01 logs]# cat test.log http://www.baidu.com/ 34 http://www.taobao.com/ 10 http://www.baidu.com/ 27 http://www.taobao.com/ 12
现在需要统计各个url的平均响应时间,并按照递减顺序排名,一条命令如何实现:
[root@ecs01 logs]# cat test.log |awk '{url[$1]+=$2;curl[$1]++}END{for(i in url)for(c in curl)if (c=i) print c,url[i]/curl[c]}'|uniq|sort -k2 -rn http://www.baidu.com/ 30.5 http://www.taobao.com/ 11
拿自己的网站日志测试下:
[root@ecs01 logs]# tail access.log -n200|awk -F'[" ]+' '{url[$7]+=$9;curl[$7]++}END{for(i in url)for(c in curl)if (c=i) print c,url[i]/curl[c]}'|uniq|sort -k2 -rn|head http://pyops.net/zb_users/theme/koilee/style/style.css 139511 http://pyops.net/?id=51 94067 http://pyops.net/zb_system/script/jquery-2.2.4.min.js 85578 http://pyops.net/zb_users/upload/2019/05/201905141557772239461811.jpg 83907 http://pyops.net/zb_users/theme/koilee/style/style.css 69755.5 http://pyops.net/zb_users/plugin/UEditor/third-party/prism/prism.js 61083 http://pyops.net/zb_users/plugin/UEditor/third-party/prism/prism.js 61083 http://pyops.net/?id=33 52397 http://pyops.net/zb_users/theme/koilee/script/swiper.min.js 51247 http://pyops.net/zb_users/theme/koilee/script/swiper.min.js 51247
发表评论