Site Access status and time-out monitoring alarm settings

Source: Internet
Author: User

Because of the company's business is more, deployed more sites. For the safe operation of the website, in case of failure to be able to know the first time, deliberately write the following monitoring script, the site Access status and time-out monitoring: When the code status of 5xx or access time-out is greater than 10s alarm. The script script is as follows:

[[email protected] web_monit]$ pwd/app/script/web_monit[[email protected] web_monit]$ lltotal 12-             Rwxr-xr-x 1 root root 870 Oct 21:34 http_monit.sh//Monitoring script-rwxr-xr-x 1 root root 857 Oct 21:25 sms.py SMS alarm script with alarm contact-rw-r--r--1 root root 377 Oct 21:27 weblist.txt//Monitored website domain name list [email protecte  D] web_monit]$ cat http_monit.sh #!/bin/shweblist=/app/script/web_monit/weblist.txt for list in ' Cat $weblist |grep-e-V "#|^$" ' dohttpcode= ' Curl-o/dev/null-s-w%{http_code} "$list" ' Httptime= ' CU Rl-o/dev/null-s-W "time_connect:%{time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_ total}\n "" $list "|grep time_total|awk-f": "' {print $2*1000} ' if [$httpcode = 500]| | [$httpcode = 502]| | [$httpcode = 503]| | [$httpcode = 504]then python/app/script/web_monit/sms.py $list "$list access Error! Status code for $httpcode! please check and process as soon as possible after receiving the alarm!" else echo "$list is checked ok!" Fiif [$httptime-ge 10000] then python/app/script/web_monit/sms.py $list "$list Access Timeout! The time-out is $httptime milliseconds! Please check and process as soon as possible after receiving the alarm!" else echo "$list is connect ok!" Fidone

Manually check the code status code for website access

[Email protected] web_monit]$ Curl-o/dev/null-s-W%{http_code} http://www.wang.com200

Manually check the time-out for website access (in milliseconds, 0.8 seconds for the following URLs)

[Email protected] web_monit]$ Curl-o/dev/null-s-W "time_connect:%{time_connect}\ntime_starttransfer:%{time_ Starttransfer}\ntime_total:%{time_total}\n "http://www.wang.com |grep time_total|awk-f": "' {print $2*1000} ' 800

Site list and script execution

[[email protected] web_monit] $cat weblist.txt http://nop.kevin.cnhttp://ap.kevin.cnhttp://ope.kevin.cnhttp:/ /opr.kevin.cnhttp://www.kevin.cn http://kevin.cn http://tb.kevin.cnhttp://www.wang.comhttps://www.wang.comhttp:/ /doc.kevin.cnhttp://docs.kevin.cnhttp://git.wang.comhttp://monitor.kevin.cnhttp://dash.kevin.cn[[email  Protected] Web_monit] $sh http_monit.sh http://nop.kevin.cn is checked ok!http://nop.kevin.cn is connect ok!http:// Ap.kevin.cn is checked ok!http://ap.kevin.cn is connect ok!http://ope.kevin.cn are checked ok!http://ope.kevin.cn is Conne CT ok!http://opr.kevin.cn is checked ok!http://opr.kevin.cn are connect ok!http://www.kevin.cn is checked ok!http:// Www.kevin.cn is connect ok!http://kevin.cn is checked ok!http://kevin.cn are connect ok!http://tb.kevin.cn is checked ok!ht Tp://tb.kevin.cn is connect ok!http://www.wang.com are checked ok!http://www.wang.com is connect ok!https://www.wang.com is checked ok!https://www.wang.com are connect ok!http://doc.kevin.cn is Checked ok!http://doc.kevin.cn is connect ok!http://docs.kevin.cn are checked ok!http://docs.kevin.cn is connect ok!http:// Git.wang.com is checked ok!http://git.wang.com are connect ok!http://monitor.kevin.cn is checked ok!http:// Monitor.kevin.cn is connect ok!http://dash.kevin.cn are checked ok!http://dash.kevin.cn is connect ok!

Scheduled monitoring tasks (monitored every two minutes)

[[email protected] web_monit]$ CRONTAB-L*/2 * * * */bin/bash-x/app/script/web_monit/http_monit.sh  >/dev/null 2 >&1

Simple note: comparison operators only = = and! = are used for string comparisons, not for integer comparisons, and for integer comparisons only with-eq,-gt this form

Site Access status and time-out monitoring alarm settings

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.