9.1 QLabel標籤展示控制元件
阿新 • • 發佈:2022-04-13
文章節選自《Netkiller Monitoring 手札》
20.2. Web
20.2.1. Apache Log
1、檢視當天有多少個IP訪問: awk '{print $1}' log_file|sort|uniq|wc -l 2、檢視某一個頁面被訪問的次數: grep "/index.php" log_file | wc -l 3、檢視每一個IP訪問了多少個頁面: awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file 4、將每個IP訪問的頁面數進行從小到大排序: awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file | sort -n 5、檢視某一個IP訪問了哪些頁面: grep ^111.111.111.111 log_file| awk '{print $1,$7}' 6、去掉搜尋引擎統計當天的頁面: awk '{print $12,$1}' log_file | grep ^"Mozilla | awk '{print $2}' |sort | uniq | wc -l 7、檢視2009年6月21日14時這一個小時內有多少IP訪問: awk '{print $4,$1}' log_file | grep 21/Jun/2009:14 | awk '{print $2}'| sort | uniq | wc -l
20.2.1.1. 刪除日誌
刪除一個月前的日誌
rm -f /www/logs/access.log.$(date -d '-1 month' +'%Y-%m')*
20.2.1.2. 統計爬蟲
grep -E 'Googlebot|Baiduspider' /www/logs/www.example.com/access.2011-02-23.log | awk '{ print $1 }' | sort | uniq
20.2.1.3. 統計瀏覽器
cat /www/logs/example.com/access.2010-09-20.log | grep -v -E 'MSIE|Firefox|Chrome|Opera|Safari|Gecko|Maxthon' | sort | uniq -c | sort -r -n | head -n 100
20.2.1.4. IP 統計
# grep '22/May/2012' /tmp/myid.access.log | awk '{print $1}' | awk -F'.' '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -r -n | head -n 10 2206 219.136.134.13 1497 182.34.15.248 1431 211.140.143.100 1431 119.145.149.106 1427 61.183.15.179 1427 218.6.8.189 1422 124.232.150.171 1421 106.187.47.224 1420 61.160.220.252 1418 114.80.201.18
統計網段
# cat /www/logs/www/access.2010-09-20.log | awk '{print $1}' | awk -F'.' '{print $1"."$2"."$3".0"}' | sort | uniq -c | sort -r -n | head -n 200
壓縮檔案處理
zcat www.example.com.access.log-20130627.gz | grep '/xml/data.json' | awk '{print $1}' | awk -F'.' '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -r -n | head -n 20
20.2.1.5. 統計域名
# cat /www/logs/access.2011-07-27.log |awk '{print $2}'|sort|uniq -c|sort -rn|more
20.2.1.6. HTTP Status
# cat /www/logs/access.2011-07-27.log |awk '{print $9}'|sort|uniq -c|sort -rn|more
5056585 304
1125579 200
7602 400
5 301
20.2.1.7. URL 統計
cat /www/logs/access.2011-07-27.log |awk '{print $7}'|sort|uniq -c|sort -rn|more
20.2.1.8. 檔案流量統計
cat /www/logs/access.2011-08-03.log |awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}'|sort -rn|more
grep ' 200 ' /www/logs/access.2011-08-03.log |awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}'|sort -rn|more
20.2.1.9. URL訪問量統計
# cat www.access.log | awk '{print $7}' | egrep '?|&' | sort | uniq -c | sort -rn | more
20.2.1.10. 指令碼執行速度
查出執行速度最慢的指令碼
grep -v 0$ access.2010-11-05.log | awk -F '" ' '{print $4" " $1}' web.log | awk '{print $1" "$8}' | sort -n -k 1 -r | uniq > /tmp/slow_url.txt
20.2.1.11. IP, URL 抽取
# tail -f /www/logs/www.365wine.com/access.2012-01-04.log | grep '/test.html' | awk '{print $1" "$7}'