awk統計訪問nginx日誌次數

往事已成昨天發表於2024-06-03

###查詢nginx日誌的訪問IP次數
[root@localhost nginx]# awk '{a[$3]++}END{for (v in a)print v,a[v]}' access.log |grep 192.168.1.33
192.168.1.33 38018
[root@localhost nginx]#

###查詢nginx的狀態碼次數,統計192.168.1.33、192.168.1.10訪問日誌裡面的狀態碼次數
[root@localhost nginx]# grep 192.168.1.33 access.log |head -20
[root@localhost nginx]# grep 192.168.1.33 access.log |head -20 |awk '{a[$11]++}END{for (v in a)print v,a[v]}'
200 20

[root@localhost nginx]# grep -c 192.168.1.10 .access.log
562
[root@localhost nginx]# grep 192.168.1.10 access.log |awk '{a[$11]++}END{for (v in a)print v,a[v]}'
403 562

###查詢nginx日誌的訪問IP次數
[root@localhost nginx]# awk '{a[$3]++}END{for (v in a)print v,a[v]}' access.log|grep 192.168.1.33
192.168.1.33 38018
[root@localhost nginx]#

###查詢nginx的狀態碼次數,統計192.168.1.33、192.168.1.10訪問日誌裡面的狀態碼次數
[root@localhost nginx]# grep 192.168.1.33 access.log |head -20
[root@localhost nginx]# grep 192.168.1.33 access.log |head -20 |awk '{a[$11]++}END{for (v in a)print v,a[v]}'
200 20

[root@localhost nginx]# grep -c 192.168.1.10 access.log
562
[root@localhost nginx]# grep 192.168.1.10 access.log |awk '{a[$11]++}END{for (v in a)print v,a[v]}'
403 562

相關文章