Nginx combined with Shell statistics user's UV and IP summary

Source: Internet
Author: User
Tags ip number

The company's new demand, suspected PV and IP ratio is not right, see if there is malicious east:

Nginx Configuration:

Log_format  main                      ""                       $http _user_agent "" $http _x_cookie "" $request _time "" $upstream _response_time "" $upstream _cache_status "" $uid " ';
" - " ;         if " uid= (\s+) (;. *|$){            set $uid $1;        }    

PV Top 20 Leaderboard:

 cat  test.log| sort  | awk     $NF!~/-/{print $ "," $NF}   " | uniq  | awk -F,  {print $   " | 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

Total IP number of the company:

Cat Test.log| Sort| awk ' $NF!~/-/{print $ "," $NF} '| Uniq | awk -F  '{print $}'|  Uniq -c| Sort -nr| WC -L

32

Total UV number of the company:

Cat Test.log| Sort| awk ' $NF!~/-/{print $ "," $NF} '| Uniq | awk -F  '{print $}'|  Uniq -c| Sort -nr| awk ' Begin{total=0}{total=total+$1}end{print "UV is:" Total} '

UV is:43

Nginx combined with Shell statistics user's UV and IP summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.