NGINX日志分析
nginx log 格式
log_format access '$http_x_forwarded_for $remote_addr $remote_user [$time_local]' | |
'"http://$host" "$request" $status $body_bytes_sent "$http_referer"' | |
'"$http_user_agent" "$HTTP_X_UP_CALLING_LINE_ID" "$request_time"'; |
1. 获得访问前 10 位的 ip 地址
cat access.log|gawk '{print $1}' |sort|uniq -c|sort -nr|head -10 |
2. 访问次数最多的文件或页面
cat access.log|gawk '{print $11}'|sort|uniq -c|sort -nr |
3. 通过子域名访问次数,依据 referer 来计算(稍有不准)
cat access.log|awk '{print $11}'|sed -e ' s/http:\/\///' -e ' s/\/.*//'|sort|uniq -c|sort -rn|head -20 |
4. 列出传输大小最大的几个文件
cat access.log|awk '($7~/\.php/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -100 |