Linux 統(tǒng)計(jì)Web服務(wù)日志命令
共 11415字,需瀏覽 23分鐘
·
2024-07-05 17:42
閱讀目錄
Apache日志統(tǒng)計(jì)
Nginx 日志統(tǒng)計(jì)
統(tǒng)計(jì)Web服務(wù)狀態(tài)
其他統(tǒng)計(jì)組合
次數(shù)統(tǒng)計(jì)
本人在Linux運(yùn)維中收集的一些通用的統(tǒng)計(jì),Apache/Nginx服務(wù)器日志的命令組合。
Apache日志統(tǒng)計(jì)
# 列出當(dāng)天訪問次數(shù)最多的IP命令[[email protected] httpd]# cut -d- -f 1 access_log | uniq -c | sort -rn | head -20# 查看當(dāng)天有多少個(gè)IP訪問[[email protected] httpd]# awk '{print $1}' access_log | sort | uniq | wc -l# 查看某一個(gè)頁面總計(jì)被訪問的次數(shù)[[email protected] httpd]# cat access_log | grep "index.php" | wc -l# 查看每一個(gè)IP訪問了多少個(gè)頁面[[email protected] httpd]# awk '{++S[$1]} END {for (a in S) print a,S[a]}' access_log# 將每個(gè)IP訪問的頁面數(shù)進(jìn)行從小到大排序[[email protected] httpd]# awk '{++S[$1]} END {for (a in S) print S[a],a}' access_log | sort -n# 查看某一個(gè)IP訪問了哪些頁面[[email protected] httpd]# grep "^192.168.1.2" access_log | awk '{print $1,$7}'# 去掉搜索引擎統(tǒng)計(jì)當(dāng)天的頁面[[email protected] httpd]# awk '{print $12,$1}' access_log | grep ^"Mozilla" | awk '{print $2}' |sort | uniq | wc -l# 查看21/Nov/2019:03:40:26這一個(gè)小時(shí)內(nèi)有多少IP訪問[[email protected] httpd]# awk '{print $4,$1}' access_log | grep "21/Nov/2019:03:40:26" | awk '{print $2}'| sort | uniq | wc -l
Nginx 日志統(tǒng)計(jì)
# 列出所有的IP訪問情況[[email protected] httpd]# awk '{print $1}' access_log | sort -n | uniq# 查看訪問最頻繁的前100個(gè)IP[[email protected] httpd]# awk '{print $1}' access_log | sort -n | uniq -c | sort -rn | head -n 100# 查看訪問100次以上的IP[[email protected] httpd]# awk '{print $1}' access_log | sort -n | uniq -c | awk '{if($1 >100) print $0}' | sort -rn# 查詢某個(gè)IP的詳細(xì)訪問情況,按訪問頻率排序[[email protected] httpd]# grep '192.168.1.2' access_log | awk '{print $7}' | sort | uniq -c | sort -rn | head -n 100# 頁面訪問統(tǒng)計(jì):查看訪問最頻繁的前100個(gè)頁面[[email protected] httpd]# awk '{print $7}' access_log | sort | uniq -c | sort -rn | head -n 100# 頁面訪問統(tǒng)計(jì):查看訪問最頻繁的前100個(gè)頁面(排除php|py)[[email protected] httpd]# grep -E -v ".php|.py" access_log | awk '{print $7}' | sort |uniq -c | sort -rn | head -n 100# 頁面訪問統(tǒng)計(jì):查看頁面訪問次數(shù)超過100次的頁面[[email protected] httpd]# cat access_log | cut -d ' ' -f 7 | sort |uniq -c | awk '{if ($1 > 100) print$0}'# 頁面訪問統(tǒng)計(jì):查看最近1000條記錄中,訪問量最高的頁面[[email protected] httpd]# tail -1000 access_log | awk '{print $7}' | sort | uniq -c | sort -nr# 每秒請求量統(tǒng)計(jì):統(tǒng)計(jì)每秒的請求數(shù)前100的時(shí)間點(diǎn)(精確到秒)[[email protected] httpd]# awk '{print $4}' access_log | cut -c14-21 | sort | uniq -c | sort -nr | head -n 100# 每分鐘請求量統(tǒng)計(jì) 11、統(tǒng)計(jì)每分鐘的請求數(shù),top100的時(shí)間點(diǎn)(精確到分鐘)[[email protected] httpd]# awk '{print $4}' access_log | cut -c14-18 | sort | uniq -c | sort -nr | head -n 100# 每小時(shí)請求量統(tǒng)計(jì) 12、統(tǒng)計(jì)每小時(shí)的請求數(shù),top100的時(shí)間點(diǎn)(精確到小時(shí))[[email protected] httpd]# awk '{print $4}' access_log | cut -c14-15 | sort | uniq -c | sort -nr | head -n 100
統(tǒng)計(jì)Web服務(wù)狀態(tài)
# 統(tǒng)計(jì)網(wǎng)站爬蟲[[email protected] httpd]# grep -E 'Googlebot|Baiduspider' access_log | awk '{ print $1 }' | sort | uniq# 統(tǒng)計(jì)網(wǎng)站中瀏覽器的訪問情況[[email protected] httpd]# cat access_log | grep -v -E 'MSIE|Firefox|Chrome|Opera|Safari|Gecko|Maxthon' | sort | uniq -c | sort -r -n | head -n 100# 統(tǒng)計(jì)網(wǎng)段分布情況[[email protected] httpd]# cat access_log | awk '{print $1}' | awk -F'.' '{print $1"."$2"."$3".0"}' | sort | uniq -c | sort -r -n | head -n 200# 統(tǒng)計(jì)來訪域名[[email protected] httpd]# cat access_log | awk '{print $2}' | sort | uniq -c | sort -rn | more# 統(tǒng)計(jì)HTTP狀態(tài)[[email protected] httpd]# cat access_log | awk '{print $9}' | sort | uniq -c | sort -rn | more# URL訪問次數(shù)統(tǒng)計(jì)[[email protected] httpd]# cat access_log | awk '{print $7}' | sort | uniq -c | sort -rn | more# URL訪問流量統(tǒng)計(jì)[[email protected] httpd]# cat access_log | awk '{print $7}' | egrep '?|&' | sort | uniq -c | sort -rn | more# 文件流量統(tǒng)計(jì)[[email protected] httpd]# cat access_log | awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}' | \sort -rn | more | grep '200' access_log | \awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}' | sort -rn | more
其他統(tǒng)計(jì)組合
# 列出當(dāng)天訪問次數(shù)最多的IP命令[[email protected] httpd]# cut -d- -f 1 access_log | uniq -c | sort -rn | head -20# 查看當(dāng)天有多少個(gè)IP訪問[[email protected] httpd]# awk '{print $1}' access_log | sort | uniq | wc -l# 查看某一個(gè)頁面總計(jì)被訪問的次數(shù)[[email protected] httpd]# cat access_log | grep "index.php" | wc -l# 查看每一個(gè)IP訪問了多少個(gè)頁面[[email protected] httpd]# awk '{++S[$1]} END {for (a in S) print a,S[a]}' access_log# 將每個(gè)IP訪問的頁面數(shù)進(jìn)行從小到大排序[[email protected] httpd]# awk '{++S[$1]} END {for (a in S) print S[a],a}' access_log | sort -n# 查看某一個(gè)IP訪問了哪些頁面[[email protected] httpd]# grep "^192.168.1.2" access_log | awk '{print $1,$7}'# 去掉搜索引擎統(tǒng)計(jì)當(dāng)天的頁面[[email protected] httpd]# awk '{print $12,$1}' access_log | grep ^"Mozilla" | awk '{print $2}' |sort | uniq | wc -l# 查看21/Nov/2019:03:40:26這一個(gè)小時(shí)內(nèi)有多少IP訪問[[email protected] httpd]# awk '{print $4,$1}' access_log | grep "21/Nov/2019:03:40:26" | awk '{print $2}'| sort | uniq | wc -lNginx日志統(tǒng)計(jì):# 列出所有的IP訪問情況[[email protected] httpd]# awk '{print $1}' access_log | sort -n | uniq# 查看訪問最頻繁的前100個(gè)IP[[email protected] httpd]# awk '{print $1}' access_log | sort -n | uniq -c | sort -rn | head -n 100# 查看訪問100次以上的IP[[email protected] httpd]# awk '{print $1}' access_log | sort -n | uniq -c | awk '{if($1 >100) print $0}' | sort -rn# 查詢某個(gè)IP的詳細(xì)訪問情況,按訪問頻率排序[[email protected] httpd]# grep '192.168.1.2' access_log | awk '{print $7}' | sort | uniq -c | sort -rn | head -n 100# 頁面訪問統(tǒng)計(jì):查看訪問最頻繁的前100個(gè)頁面[[email protected] httpd]# awk '{print $7}' access_log | sort | uniq -c | sort -rn | head -n 100# 頁面訪問統(tǒng)計(jì):查看訪問最頻繁的前100個(gè)頁面(排除php|py)[[email protected] httpd]# grep -E -v ".php|.py" access_log | awk '{print $7}' | sort |uniq -c | sort -rn | head -n 100# 頁面訪問統(tǒng)計(jì):查看頁面訪問次數(shù)超過100次的頁面[[email protected] httpd]# cat access_log | cut -d ' ' -f 7 | sort |uniq -c | awk '{if ($1 > 100) print$0}'# 頁面訪問統(tǒng)計(jì):查看最近1000條記錄中,訪問量最高的頁面[[email protected] httpd]# tail -1000 access_log | awk '{print $7}' | sort | uniq -c | sort -nr# 每秒請求量統(tǒng)計(jì):統(tǒng)計(jì)每秒的請求數(shù)前100的時(shí)間點(diǎn)(精確到秒)[[email protected] httpd]# awk '{print $4}' access_log | cut -c14-21 | sort | uniq -c | sort -nr | head -n 100# 每分鐘請求量統(tǒng)計(jì) 11、統(tǒng)計(jì)每分鐘的請求數(shù),top100的時(shí)間點(diǎn)(精確到分鐘)[[email protected] httpd]# awk '{print $4}' access_log | cut -c14-18 | sort | uniq -c | sort -nr | head -n 100# 每小時(shí)請求量統(tǒng)計(jì) 12、統(tǒng)計(jì)每小時(shí)的請求數(shù),top100的時(shí)間點(diǎn)(精確到小時(shí))[[email protected] httpd]# awk '{print $4}' access_log | cut -c14-15 | sort | uniq -c | sort -nr | head -n 100統(tǒng)計(jì)其他頁面數(shù)據(jù):# 統(tǒng)計(jì)網(wǎng)站爬蟲[[email protected] httpd]# grep -E 'Googlebot|Baiduspider' access_log | awk '{ print $1 }' | sort | uniq# 統(tǒng)計(jì)網(wǎng)站中瀏覽器的訪問情況[[email protected] httpd]# cat access_log | grep -v -E 'MSIE|Firefox|Chrome|Opera|Safari|Gecko|Maxthon' | sort | uniq -c | sort -r -n | head -n 100# 統(tǒng)計(jì)網(wǎng)段分布情況[[email protected] httpd]# cat access_log | awk '{print $1}' | awk -F'.' '{print $1"."$2"."$3".0"}' | sort | uniq -c | sort -r -n | head -n 200# 統(tǒng)計(jì)來訪域名[[email protected] httpd]# cat access_log | awk '{print $2}' | sort | uniq -c | sort -rn | more# 統(tǒng)計(jì)HTTP狀態(tài)[[email protected] httpd]# cat access_log | awk '{print $9}' | sort | uniq -c | sort -rn | more# URL訪問次數(shù)統(tǒng)計(jì)[[email protected] httpd]# cat access_log | awk '{print $7}' | sort | uniq -c | sort -rn | more# URL訪問流量統(tǒng)計(jì)[[email protected] httpd]# cat access_log | awk '{print $7}' | egrep '?|&' | sort | uniq -c | sort -rn | more# 文件流量統(tǒng)計(jì)[[email protected] httpd]# cat access_log | awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}' | \sort -rn | more | grep '200' access_log | \awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}' | sort -rn | more
次數(shù)統(tǒng)計(jì)
查看某一個(gè)頁面被訪問的次數(shù)[[email protected] httpd]# grep "/index.php" log_file | wc -l查看每一個(gè)IP訪問了多少個(gè)頁面[[email protected] httpd]# awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file將每個(gè)IP訪問的頁面數(shù)進(jìn)行從小到大排序[[email protected] httpd]# awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file | sort -n查看某一個(gè)IP訪問了哪些頁面[[email protected] httpd]# grep ^111.111.111.111 log_file| awk '{print $1,$7}'去掉搜索引擎統(tǒng)計(jì)當(dāng)天的頁面[[email protected] httpd]# awk '{print $12,$1}' log_file | grep ^"Mozilla | awk '{print $2}' |sort | uniq | wc -l查看2018年6月21日14時(shí)這一個(gè)小時(shí)內(nèi)有多少IP訪問[[email protected] httpd]# awk '{print $4,$1}' log_file | grep 21/Jun/2018:14 | awk '{print $2}'| sort | uniq | wc -l統(tǒng)計(jì)爬蟲[[email protected] httpd]# grep -E 'Googlebot|Baiduspider' /www/logs/access.2019-02-23.log | awk '{ print $1 }' | sort | uniq統(tǒng)計(jì)瀏覽器[[email protected] httpd]# cat /www/logs/access.2019-02-23.log | grep -v -E 'MSIE|Firefox|Chrome|Opera|Safari|Gecko|Maxthon' | sort | uniq -c | sort -r -n | head -n 100IP 統(tǒng)計(jì)[[email protected] httpd]# grep '23/May/2019' /www/logs/access.2019-02-23.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統(tǒng)計(jì)網(wǎng)段[[email protected] httpd]# cat /www/logs/access.2019-02-23.log | awk '{print $1}' | awk -F'.' '{print $1"."$2"."$3".0"}' | sort | uniq -c | sort -r -n | head -n 200統(tǒng)計(jì)域名[[email protected] httpd]# cat /www/logs/access.2019-02-23.log |awk '{print $2}'|sort|uniq -c|sort -rn|moreHTTP狀態(tài)[[email protected] httpd]# cat /www/logs/access.2019-02-23.log |awk '{print $9}'|sort|uniq -c|sort -rn|more5056585 3041125579 200 7602 400 5 301URL 統(tǒng)計(jì)[[email protected] httpd]# cat /www/logs/access.2019-02-23.log |awk '{print $7}'|sort|uniq -c|sort -rn|more文件流量統(tǒng)計(jì)[[email protected] httpd]# cat /www/logs/access.2019-02-23.log |awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}'|sort -rn|moregrep ' 200 ' /www/logs/access.2019-02-23.log |awk '{sum[$7]+=$10}END{for(i in sum){print sum[i],i}}'|sort -rn|moreURL訪問量統(tǒng)計(jì)[[email protected] httpd]# cat /www/logs/access.2019-02-23.log | awk '{print $7}' | egrep '?|&' | sort | uniq -c | sort -rn | more查出運(yùn)行速度最慢的腳本[[email protected] httpd]# grep -v 0$ /www/logs/access.2019-02-23.log | awk -F '" ' '{print $4" " $1}' web.log | awk '{print $1" "$8}' | sort -n -k 1 -r | uniq > /tmp/slow_url.txtIP, URL 抽取[[email protected] httpd]# tail -f /www/logs/access.2019-02-23.log | grep '/test.html' | awk '{print $1" "$7}'
鏈接:https://www.cnblogs.com/LyShark/p/12500145.html
(版權(quán)歸原作者所有,侵刪)
評論
圖片
表情
