nginx访问日志分析
通过脚本对nginx访问日志进行分析
脚本内容如下
#!/bin/bash
#日志格式:$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"
LOG_FILE=$1
echo "统计访问最多的10个IP"
awk '{a[$1]++}END{print "PV:",length(a);for(v in a)print v,a[v]}' $LOG_FILE |sort -k2 -nr |head -n 10
echo "--------------------"
echo "统计时间段访问最多的IP"
awk '$4>="[07/Jun/2021:17:56:05 +0800]" && $4<="[10/May/2022:22:07:29 +0800]"{a[$1]++}END{for (v in a)print v,a[v]}' $LOG_FILE |sort -k2 -nr |head -n 10
echo "--------------------"
echo "统计访问最多的10个页面"
awk '{a[$7]++}END{print "UV:",length(a);for(v in a){if(a[v]>10)print v,a[v]}}' $LOG_FILE |sort -k2 -nr
echo "--------------------"
echo "统计访问页面状态码数量"
awk '{a[$7" "$9]++}END{for(v in a){if(a[v]>5)print v,a[v]}}' $LOG_FILE |sort -k3 -nr
echo "--------------------"
输出结果
本文来自博客园,作者:霸都运维,转载请注明原文链接:https://www.cnblogs.com/wangjie20200529/p/16307978.html