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

来源:互联网 发布:自学游戏编程 编辑:程序博客网 时间:2024/05/21 01:55

转自:http://sesame.iteye.com/blog/1678326

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

Log代码  收藏代码
  1. 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代码  收藏代码
  1. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  
  2. LogFormat "%h %l %u %t \"%r\" %>s %b" common  

 

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

 

写了一行shell脚本:

 

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

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

 

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

 

 

结果代码  收藏代码
  1. 2713 /172.22.14.109/ok.htm  
  2. 2387 /*/order/orderList.htm  
  3. 1009 /*/favicon.ico  
  4.  990 /*/index.htm  
  5.  854 /*/wide/jhs/wlTrace.htm  
  6.  851 /*/aita/css/aita-main.css  
  7.  780 /*/order/orderDetail.htm  
  8.  715 /*/storage/stockInList.json  
  9.  519 /*/determine/deduce.json  
  10.  496 /*/order/channelOrderListLimit.json  
0 0
原创粉丝点击