您的位置:首页 > 运维架构 > 网站架构

一行代码了解网站被访问最多的URL

2016-09-15 23:42 387 查看
转自:http://sesame.iteye.com/blog/1678326

有需求想分析下网站的被访问的TOP 10 URL是哪些,想到了apache 的cookie日志中有记录,在日志目录的cookie_log.*文件中,打开一个确实存在:

Log代码  


112.113.241.58 - - - [09/Sep/2012:00:01:08 +0800] "GET /dd.abc.com/favicon.ico HTTP/1.1" 200 1406 154 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) QQBrowser/6.0"  

 

不过对每一个列对应的含义不是很清楚,看了下httpd.conf,

 

Html代码  


LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  

LogFormat "%h %l %u %t \"%r\" %>s %b" common  

 

查了下apache的配置文档,了解了对应的含义。

 

写了一行shell脚本:

 

Shell代码  


cat cookie_log.0 | awk '{ print $8 }' | sed s/?.*//g |sort | uniq -c | sort -n -r |head -n 10  

 (uniq这个命令默认只删除紧挨的重复行,所以需要先sort下,再uniq)

 

得到以下结果,(具体网址用手动替换成*了)

 

 

结果代码  


2713 /172.22.14.109/ok.htm  

2387 /*/order/orderList.htm  

1009 /*/favicon.ico  

 990 /*/index.htm  

 854 /*/wide/jhs/wlTrace.htm  

 851 /*/aita/css/aita-main.css  

 780 /*/order/orderDetail.htm  

 715 /*/storage/stockInList.json  

 519 /*/determine/deduce.json  

 496 /*/order/channelOrderListLimit.json  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: