zoukankan      html  css  js  c++  java
  • 统计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

  • 相关阅读:
    jquery 移除数组重复的元素----$.unique()
    jQuery UI 日期控件--datepicker
    jQuery 如何设置input checkbox 更有效 prop()
    while loading persisted sessions 异常解决方法
    eclipse总是自动跳到ThreadPoolExecutor.java
    oracle的学习 第二节:创建数据表
    oracle是数据库的学习第一节:数据库的安装
    解决IE无法解析json的方法
    浏览器兼容问题----Firefox不兼容event的解决方法
    VSCode变换python的调试解释器
  • 原文地址:https://www.cnblogs.com/zhutianpeng/p/4249904.html
Copyright © 2011-2022 走看看