Use shell script to analyze Web log statistics PV, 404, 500 and other data _linux shell

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.