How to monitor whether a running service is healthy and mail alerts

Source: Internet
Author: User

Monitoring services, which are placed on crontab tasks, individuals do not like to use a dead loop to run in the background.


So every time 3 cycles are executed, 3 cycles in a row, and any one of the services is down, the alarm will be reported.

Popularize small knowledge, pay attention to redirect 3 kinds of writing, in fact, the effect is the same.

#!/bin/bashnmap -p 6065 10.31.6.6  | egrep  "6065/tcp open"    &>/dev/nullcode1=$?nmap -p 80 10.31.6.6  | grep  "80/tcp open   http " >/dev/null  2>&1code2=$?curl http://10.31.6.6/test.html/  >&/dev/nullcode3=$?my_mail () {mail_list= ("[email protected]"   "[email protected]"  ) Now_date= ' date  "+%y-%m-%d %t" ' for i in ${mail_list[@]}doecho -e  "webchat  is down,please check;\nip:42.62.5.100\n$now_date " | mail -s " webchat  Down "   $idone}n=1count=1while  ((n<4)) doif [  $code 1 = 0 ] & & [  $code 2 = 0 ] && [  $code 3 = 0 ]then  n=$ (($n + 1))  sleep 2else count=$ (($count + 1))  n=$ (($n + 1))  sleep 2 if  [  $count  -Eq 3 ];then  my_mail fi         fidone 


This article is from the "[email protected]" blog, please be sure to keep this source http://ribble.blog.51cto.com/3863110/1649583

How to monitor whether a running service is healthy and mail alerts

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.