The following script can count the total number of visits to the site and how many times 404,500 occur. Statistics, we can combine the monitoring of the Bora record, and then you can see whether the site traffic anomaly, whether there is an attack, at a glance. You can also determine if a Web site program has an exception, depending on how many times you see 500.
Copy Code code as follows:
#!/bin/bash
#purpose: Count Nginx or Apache or other webserver status code using Jiankongbao
#how To:run The script every 5 minutes with crontab
Log_path= "/var/log/nginx/www.jb51.net/access.log"
Becur= ' date-d ' 5 minute Ago "+%h%m%s"
Code= (' Tac $log _path | awk-v a= "$becur"-v total=0-f [':] ' {
T=$5$6$7
if (t>=a) {
code[$12]++
total++
}
else {
Exit
}
}end{
Print Code[404]?code[404]:0,code[500]?code[500]:0,total
}'
`)
C404=${code[0]}
C500=${CODE[1]}
TOTAL=${CODE[2]}
Echo-e "<pre>\nc404:${c404}\nc500:${c500}\ntotal:${total}\n</pre>" >/data/www/status/www.jb51.net.html
The last line of the script is:
Copy Code code as follows:
<pre>
c404:1102
c500:545
total:55463
</pre>
The format is written to a www.jb51.net HTML file, which is then combined with the custom monitoring of the monitoring treasure to collect the information. Very convenient, the monitoring treasure will automatically out of the chart.