Shell monitors multiple hosts

Source: Internet
Author: User

Write a script with the shell at the same time monitoring multiple hosts (monitoring host whether online, CPU, memory, hard disk, IO use status, and have the mail notification function), the big God after looking at the wrong place or have a better way to realize, please disdain pen and ink point.


First of all, the monitoring host and monitoring host to establish a trust relationship, do not understand the SSH certificate verification can be seen:

http://dragon123.blog.51cto.com/9152073/1586795


Install Mutt:

[email protected] ~]# Yum install mutt


Monitoring list:

[email protected] ~]# cat > Iplist.txt <<end> 22.22.22.128> 22.22.22.129> 22.22.22.130> 22.22.22.134> End


Monitoring scripts:

#!/bin/bashfor ip in  ' cat iplist.txt ';d oping  $ip  -c1>/dev/null  # First check whether the host is online, if online further monitoring if [ $? -eq 0 ];thenhardused= ' ssh  $ip  df -h|grep   "/$" |awk   ' {print $4} ' |cut -d% -f 1 ' memtotal= ' ssh  $ip  free  -m|grep mem|awk  ' {print $2} ' memused= ' ssh  $ip  free -m|grep Mem|awk  ' { print $3} ' mem= ' expr  $memused  \* 100 /  $memtotal ' idelcpu= ' ssh  $ip  top  -n1|grep Cpu|awk  ' {print $5} ' |cut -d '. "  -f1 ' cpuused= ' expr 100 -  $idelcpu ' if [  $mem  -gt 70 ];then          #如果内存使用高于70% Email notification echo  "warm: $ip  memory is  $mem" | mutt -s  "Monitor report"  [email protected]fiif [  $hardused  -le 80   ];then      #如果硬盘使用已高于80%The email notification echo  "warm: $ip  the hard drive capacity is more 80%" |mutt -s " Monitor report " [email protected] fifor hardid in " ssh  $ip  iostat  |grep ^sd|awk  ' {print $1} ';d o     #先取盘符iostat = ' ssh  $ip   iostat -x|grep  $hardid |awk  ' {print $12} ' |cut -d '. "  -f1 '   #取得io繁忙状态echo   $iostatif  [  $iostat  -gt 80 ];then      #如果io繁忙高于80%, the email notification echo  "IPAddress: $ip, Hard: $hardid, Iostat: $iostat" |mutt -s "warm"  [ email protected]fidoneelseecho  "Host: $ip  is not alive" |mutt -s "monitor  Report " [email protected]om   #如果主机无法ping通则邮件通知fidone


Monitor every 5 minutes (if something is wrong, and this is not resolved, you will receive an email every 5 minutes, which is very confusing):

[Email protected] ~]# CRONTAB-E

*/5 * * * * bash/root/monitor.sh


Check Email:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/57/6C/wKiom1SZix_AScEpAAGCG6cg4vw750.jpg "title=" 163. PNG "alt=" wkiom1szix_ascepaagcg6cg4vw750.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/57/69/wKioL1SZjIPRo20-AAEUCsrn_a4856.jpg "title=" 163. PNG "alt=" wkiol1szjipro20-aaeucsrn_a4856.jpg "/>

This article is from the "Dragon Love Xue qi" blog, please make sure to keep this source http://dragon123.blog.51cto.com/9152073/1594076

Shell monitors multiple hosts

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.