Nginx 日志统计分析命令

  1. 统计访问量最多的IP地址:

    awk '{print $1}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
    
  2. 统计不同状态码的出现次数:

    awk '{print $9}' /path/to/nginx/access.log | sort | uniq -c | sort -nr
    
  3. 统计访问量最多的URL:

    awk '{print $7}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
    
  4. 统计每分钟的访问量:

    awk '{print $4}' /path/to/nginx/access.log | cut -d: -f1,2 | sort | uniq -c | sort -nr
    
  5. 统计每小时的访问量:

    awk '{print $4}' /path/to/nginx/access.log | cut -d: -f1 | sort | uniq -c | sort -nr
    
  6. 统计每个IP地址访问的次数:

    awk '{count[$1]++} END {for (ip in count) print count[ip], ip}' /path/to/nginx/access.log | sort -nr
    
  7. 统计访问时间最长的URL:

    awk '{print $7, $10}' /path/to/nginx/access.log | awk '{sum[$1] += $2} END {for (url in sum) print sum[url], url}' | sort -nr | head -n 10
    
  8. 统计特定时间段内的访问情况:

    grep '12/Jul/2024:14' /path/to/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr
    
  9. 统计返回码为4xx或5xx的请求:

    awk '($9 ~ /^4/ || $9 ~ /^5/)' /path/to/nginx/access.log
    
  10. 统计来源网站(Referer):

    awk '{print $11}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
    
  11. 统计用户代理(User-Agent):

    awk -F\" '{print $6}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
    
  12. 统计每个IP地址的访问量并输出到文件:

    awk '{print $1}' /path/to/nginx/access.log | sort | uniq -c | sort -nr > /path/to/output/ip_stats.txt
    
  13. 统计访问量最多的前10个文件类型:

    awk -F\" '{print $2}' /path/to/nginx/access.log | awk -F. '{print $NF}' | sort | uniq -c | sort -nr | head -n 10
    
  14. 结合sed和awk统计指定URL的访问量:

    grep "/specific/url" /path/to/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr
    
  15. 分析访问日志中的慢请求(超过1秒):

    awk '$NF > 1 {print $0}' /path/to/nginx/access.log
    
  16. 计算平均响应时间:

    awk '{sum += $NF; count++} END {print sum/count}' /path/to/nginx/access.log
    
  17. 统计每个HTTP方法的使用频率:

    awk '{print $6}' /path/to/nginx/access.log | cut -d\" -f2 | sort | uniq -c | sort -nr
    
  18. 提取并统计特定URL路径的访问量:

    awk '$7 ~ "/specific/path"' /path/to/nginx/access.log | wc -l
    
  19. 统计特定状态码的访问记录:

    awk '$9 == "404"' /path/to/nginx/access.log
    
  20. 统计带有特定查询参数的URL访问量:

    awk '$7 ~ "param=value"' /path/to/nginx/access.log | wc -l
    
  21. 分析日志中所有请求的流量大小:

    awk '{sum += $10} END {print sum}' /path/to/nginx/access.log
    
  22. 统计响应时间超过一定阈值的请求:

    awk '$10 > 1000 {print $0}' /path/to/nginx/access.log
    
  23. 提取并统计某个特定时间段内的访问记录:

    awk '$4 >= "[12/Jul/2024:14:00:00" && $4 <= "[12/Jul/2024:15:00:00"' /path/to/nginx/access.log
    

相关推荐

  1. Nginx 日志统计分析命令

    2024-07-13 19:50:04       22 阅读
  2. nginx日志统计qps

    2024-07-13 19:50:04       38 阅读
  3. nginx日志自定义和统计处理

    2024-07-13 19:50:04       33 阅读
  4. 5.nginx常用命令日志定时切割

    2024-07-13 19:50:04       27 阅读
  5. 查看nginx日志文件

    2024-07-13 19:50:04       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 19:50:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 19:50:04       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 19:50:04       58 阅读
  4. Python语言-面向对象

    2024-07-13 19:50:04       69 阅读

热门阅读

  1. 天童美语:放假给孩子看什么地理纪录片

    2024-07-13 19:50:04       17 阅读
  2. Perl 语言开发(十三):网络编程

    2024-07-13 19:50:04       22 阅读
  3. 块设备驱动实现--模拟一个块设备

    2024-07-13 19:50:04       17 阅读
  4. Docker

    2024-07-13 19:50:04       15 阅读
  5. docker

    2024-07-13 19:50:04       20 阅读
  6. qint64 pendingDatagramSize() const;

    2024-07-13 19:50:04       20 阅读
  7. ThreadLocal有哪些应用场景?底层如何实现?

    2024-07-13 19:50:04       21 阅读
  8. IPython:提升Python编程效率的实用技巧与案例

    2024-07-13 19:50:04       19 阅读
  9. 赋值运算符.二

    2024-07-13 19:50:04       18 阅读
  10. 数据结构第25节 深度优先搜索

    2024-07-13 19:50:04       16 阅读
  11. Python面试题:如何在 Python 中发送 HTTP 请求?

    2024-07-13 19:50:04       18 阅读
  12. ThreadLocal使用的场景有哪些?

    2024-07-13 19:50:04       18 阅读