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:

Install Mutt:

[email protected] ~]# Yum install mutt

Monitoring list:

[email protected] ~]# cat > Iplist.txt <<end>>>>> 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/

Check Email:

650) this.width=650; "src=" Http:// "title=" 163. PNG "alt=" wkiom1szix_ascepaagcg6cg4vw750.jpg "/>

650) this.width=650; "src=" Http:// "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

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: 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.