關於apache access log 統計的那些事兒


統計APACHE ACCESS.LOG IP訪問記錄
可以根據自己的需要,統計很多,每個IP訪問多少個頁面等等!

cat access.log-20090904 |awk '{print $3}'|sort|uniq -c|sort -rn|wc -l

詳解:下面是一個例子:

cat 是讀取這個文件。

1147753394.079 2 220.139.141.61 TCP_DENIED/403 1354 CONNECT 222.124.24.93:25 - NONE/- text/html
1147753395.652 0 61.228.130.169 TCP_DENIED/403 1352 CONNECT 203.84.195.1:25 - NONE/- text/html
1147753395.754 0 61.228.135.187 TCP_DENIED/403 1350 CONNECT 203.86.1.30:25 - NONE/- text/html
1147753398.042 3 61.228.131.15 TCP_DENIED/403 1354 CONNECT 81.169.162.54:25 - NONE/- text/html


awk '{print $3}' 是apache log的第三個字段

220.139.141.61
61.228.130.169

[root@localhost~]# cat access.log | awk '{print $3}'

61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.99
61.228.130.187

sort是排序,

[root@localhost~]# cat access.log | awk '{print $3}'|sort

61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106

uniq -c 打印每一重復行出現的次數。

[root@localhost~]# cat access.log | awk '{print $3}'|sort|uniq -c
6 220.139.141.61
6 61.228.130.169
12 61.228.130.187
6 61.228.131.15

sort -rn 對排序求逆,n為域號,使用此域號開始分類。

[root@localhost~]# cat access.log | awk '{print $3}'|sort|uniq -c|sort -rn
24 61.228.134.106
12 61.228.130.187
6 61.228.135.187
6 61.228.134.99
6 61.228.131.15
6 61.228.130.169
6 220.139.141.61
wc -l 統計行數的

[root@localhost~]# cat access.log | awk '{print $3}'|sort|uniq -c|sort -rn|wc -l
7


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM