-
統計訪問量最多的IP地址:
awk '{print $1}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
-
統計不同狀態碼的出現次數:
awk '{print $9}' /path/to/nginx/access.log | sort | uniq -c | sort -nr
-
統計訪問量最多的URL:
awk '{print $7}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
-
統計每分鐘的訪問量:
awk '{print $4}' /path/to/nginx/access.log | cut -d: -f1,2 | sort | uniq -c | sort -nr
-
統計每小時的訪問量:
awk '{print $4}' /path/to/nginx/access.log | cut -d: -f1 | sort | uniq -c | sort -nr
-
統計每個IP地址訪問的次數:
awk '{count[$1]++} END {for (ip in count) print count[ip], ip}' /path/to/nginx/access.log | sort -nr
-
統計訪問時間最長的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
-
統計特定時間段內的訪問情況:
grep '12/Jul/2024:14' /path/to/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr
-
統計返回碼為4xx或5xx的請求:
awk '($9 ~ /^4/ || $9 ~ /^5/)' /path/to/nginx/access.log
-
統計來源網站(Referer):
awk '{print $11}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
-
統計用戶代理(User-Agent):
awk -F\" '{print $6}' /path/to/nginx/access.log | sort | uniq -c | sort -nr | head -n 10
-
統計每個IP地址的訪問量并輸出到文件:
awk '{print $1}' /path/to/nginx/access.log | sort | uniq -c | sort -nr > /path/to/output/ip_stats.txt
-
統計訪問量最多的前10個文件類型:
awk -F\" '{print $2}' /path/to/nginx/access.log | awk -F. '{print $NF}' | sort | uniq -c | sort -nr | head -n 10
-
結合sed和awk統計指定URL的訪問量:
grep "/specific/url" /path/to/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr
-
分析訪問日志中的慢請求(超過1秒):
awk '$NF > 1 {print $0}' /path/to/nginx/access.log
-
計算平均響應時間:
awk '{sum += $NF; count++} END {print sum/count}' /path/to/nginx/access.log
-
統計每個HTTP方法的使用頻率:
awk '{print $6}' /path/to/nginx/access.log | cut -d\" -f2 | sort | uniq -c | sort -nr
-
提取并統計特定URL路徑的訪問量:
awk '$7 ~ "/specific/path"' /path/to/nginx/access.log | wc -l
-
統計特定狀態碼的訪問記錄:
awk '$9 == "404"' /path/to/nginx/access.log
-
統計帶有特定查詢參數的URL訪問量:
awk '$7 ~ "param=value"' /path/to/nginx/access.log | wc -l
-
分析日志中所有請求的流量大小:
awk '{sum += $10} END {print sum}' /path/to/nginx/access.log
-
統計響應時間超過一定閾值的請求:
awk '$10 > 1000 {print $0}' /path/to/nginx/access.log
-
提取并統計某個特定時間段內的訪問記錄:
awk '$4 >= "[12/Jul/2024:14:00:00" && $4 <= "[12/Jul/2024:15:00:00"' /path/to/nginx/access.log