码迷,mamicode.com
首页 > 系统相关 > 详细

NGINX结合SHELL统计用户的UV及IP汇总

时间:2015-04-17 20:22:43      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

公司新的需求,怀疑PV和IP的比例不对,看是不是有恶意的东东:

NGINX配置:

 

log_format  main  $remote_addr - $remote_user [$time_local] "$request" 
                      $status $body_bytes_sent "$http_referer" 
                      "$http_user_agent" "$http_x_cookie" "$request_time" "$upstream_response_time" "$upstream_cache_status" "$uid";
set $uid "-";
        if ( $http_cookie ~* "uid=(\S+)(;.*|$)"){
            set $uid $1;
        }    

 

PV前二十位排行榜:

cat test.log|sort|awk $NF!~/-/ {print $1"," $NF}|uniq |awk -F  , {print $1}|uniq -c|sort -nr|head -20

12     53.27.4.22
1     61.183.86.163
1     61.183.237.146
1     58.255.215.115
1     27.154.152.131
1     223.240.50.192
1     222.94.205.228
1     219.140.69.67
1     218.89.115.155
1     218.28.77.119
1     183.63.212.176
1     183.54.95.254
1     182.107.39.76
1     163.179.53.171
1     14.130.237.192
1     124.207.249.82
1     124.128.87.134
1     124.117.198.63
1     122.224.216.242
1     121.61.112.2

 

公司总的IP数:

cat test.log|sort|awk $NF!~/-/ {print $1"," $NF}|uniq |awk -F  , {print $1}|uniq -c|sort -nr|wc -l

32

公司总的UV数:

cat test.log|sort|awk $NF!~/-/ {print $1"," $NF}|uniq |awk -F  , {print $1}|uniq -c|sort -nr|awk BEGIN{total=0}{total=total+$1}END{print "UV is:" total}

UV is:43

 

NGINX结合SHELL统计用户的UV及IP汇总

标签:

原文地址:http://www.cnblogs.com/aguncn/p/4435639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!