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

公司新的需求,怀疑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

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。