复制代码 代码如下:
#!/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.zyiz.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.zyiz.net.html
#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.zyiz.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.zyiz.net.html
脚本最后一行是以:
复制代码 代码如下:
<pre>
c404:1102
c500:545
total:55463
</pre>
c404:1102
c500:545
total:55463
</pre>
的格式写入到一个www.zyiz.net html文件,再结合监控宝的自定义监控来收集这些信息。非常的方便,监控宝会自动出图表。