• 统计nginx日志单IP访问请求数排名


    下面是我截取一段nginx日志

    127.0.0.1 - - [20/Jan/2015:10:54:02 +0800] "GET / HTTP/1.1" 200 20808 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    127.0.0.1 - - [20/Jan/2015:10:54:03 +0800] "GET /favicon.ico HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    127.0.0.1 - - [20/Jan/2015:10:54:15 +0800] "GET /index.php HTTP/1.1" 200 20806 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    127.0.0.1 - - [20/Jan/2015:10:54:23 +0800] "GET /index.html HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    127.0.0.1 - - [20/Jan/2015:10:56:08 +0800] "GET /index.html HTTP/1.1" 200 45 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    127.0.0.1 - - [20/Jan/2015:11:31:33 +0800] "GET / HTTP/1.1" 200 45 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:11:55:11 +0800] "GET / HTTP/1.1" 200 45 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:11:55:11 +0800] "GET /favicon.ico HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:11:55:11 +0800] "GET /favicon.ico HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:11:55:15 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:11:55:16 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:11:55:17 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:12:14:44 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
    192.168.60.200 - - [20/Jan/2015:12:14:45 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"

    方法一:

    awk '{++S[$1]} END {for(a in S) print a,S[a]}' nginx.log | sort -rn -k 2
    192.168.60.200 8
    127.0.0.1 6

    方法二:

    awk '{print $1}' nginx.log|sort|uniq -c|sort -nr -k1
          8 192.168.60.200
          6 127.0.0.1

    方法三:

    sed 's/- -.*$//g' nginx.log|sort|uniq -c|sort -nr -k1
          8 192.168.60.200 
          6 127.0.0.1 

     参考:http://oldboy.blog.51cto.com/2561410/1184206

          http://oldboy.blog.51cto.com/blog/2561410/1184177

  • 相关阅读:
    [语录]学习和知识建立于见解的多样性上
    [语录]要紧的是选择能干、诚实而且勤勉的人
    [EnterpriseServices]利用assembly定义我们的组件在COM+中的注册方式
    [EntLib]在SR.Strings中使用中文字符串资源
    如何让Win2000和XP SP1支持System.EnterpriseServices(XP已验证)
    [C#]使用HttpWebRequest请求远端服务器时如何加载SSL证书
    [纪事]再见,CodeArtist(下)
    [ZT]Google Web Accelerator 进一步的发展?
    [纪事]再见,CodeArtist
    [WiX]我的第一个WiX安装脚本
  • 原文地址:https://www.cnblogs.com/zhutianpeng/p/4249904.html
Copyright © 2020-2023  润新知