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

有需求想分析下网站的被访问的TOP 10 URL是哪些,想到了apache 的cookie日志中有记录,在日志目录的cookie_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,

 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脚本:

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

猜你喜欢

转载自sesame.iteye.com/blog/1678326