#!/bin/sh#count memory_used_rate,disk_used_rate # @yuanwb 2015-5 #disk_used_rate #depend on real storage place the parameter ' Location ' need to Alter. location=/dev/sda1disk_used_rate1=$ (df -h | grep $Location | awk ' {print  $5} ') free1= ' echo $Disk _used_rate1|awk -f% ' {print $1} ' subject1= ' (info) monitor /dev/sda1 hard disk space less than 95% "messagelog1=" monitor /dev/sda1 hard disk space usage is $Disk _used_rate1 " Subject2= "(warn) monitor /dev/sda1 hard disk space greater than 95%" messagelog2= "monitor /dev/sda1 hard disk space utilization for $Disk _used_rate1 "if [ $free 1 -lt 95 ];then/usr/local/bin/sendemail - s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 1" -m "$messagelog 1" else/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 2" -m "$messagelog 2" filocation=/dev/sda2disk_used_rate2=$ (df -h | grep $Location | awk ' {print $5} ') echo $Disk _used_rate2free1= ' echo $Disk _ used_rate2|awk -f% ' {print $1} ' subject1= ' (info) monitor /dev/sda2 hard disk space less than 95% " messagelog1= "monitor /dev/sda2 hard disk space usage is $Disk _used_rate2 " subject2= "(warn) monitor /dev/sda2 hard disk space is greater than 95% "messagelog2=" monitor /dev/sda2 hard disk space utilization is $Disk _used_rate2 " if [ $free 1 -lt 95 ];then/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "utf-8 " -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 1" -m "$messagelog 1" else/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= " UTF-8 " -xu [email protected] -xp 1234565 -f [email protected] -t mo[email protected],[email protected],[email protected] -u "$subject 2" -m "$messagelog 2" filocation=/dev/sdb1disk_used_rate3=$ (df -h | grep $Location | awk ' {print $5} ') echo $Disk _used_rate3free1= ' echo $Disk _used_rate3|awk -f% ' {print $1} ' subject1= ' (info) monitor /dev/sdb1 hard disk space less than 95% "messagelog1=" monitor /dev/sdb1 Hard disk space usage is $Disk _used_rate3 "subject2=" (warn) monitor /dev/sdb1 hard disk space greater than 95 % "Messagelog2=" Monitor /dev/sdb1 Hard disk space usage is $Disk _used_rate3 "if [ $free 1 -lt 95 ];then/usr/local/ bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[ email protected],[email protected] -u "$subject 1" -m "$messagelog 1" else/usr/ local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[ email protected],[email protected] -u "$subject 2" -m "$messagelog 2" fi # memory_used_rateloadmemory=$ (cat /proc/meminfo | awk ' {print $2} ') Total=$ (echo $ loadmemory | awk ' {print $1} ') free1=$ (echo $LoadMemory | awk ' {print $2} ') free2=$ (echo $LoadMemory | awk ' {print $3} ') free3=$ (echo $LoadMemory | awk ' {print $ 4} ') used= ' expr $Total - $Free 1 - $Free 2 - $Free 3 ' used_rate= ' expr $Used/$Total *100 | bc -l ' memory_used_rate= ' expr $Used _rate/1 |  BC ' echo $Memory _used_rate%free1= ' echo $Memory _used_rate%|awk -f% ' {print $1} ' subject1= "(info) monitor memory usage is less than 90%" messagelog1= "monitor memory usage is $Memory _used_rate " Subject2= "(Error) monitor memory usage is greater than 90%" messagelog2= "monitor memory usage is $Memory _used_rate " if [ $free 1 -lt 90 ];then/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 1" -m "$messagelog 1" else/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [ email protected],[email protected],[email protected] -u "$subject 2" -m "$ Messagelog2 "fi#!/bin/bashping -c 20 -i 0.1 222.240.205.161 > test.txtb=" cat test.txt|grep "Packet loss" |awk ' {print $6} ' |awk -f% ' {print $1} ' subject1= "(info) 220.240.X.X Gateway packet loss rate less than 5%" messagelog= "Gateway packet loss rate monitoring success!!" Subject2= "(warn) 220.240.X.X Gateway packet loss rate greater than 5%" messagelog1= "Gateway packet loss rate monitoring is unsuccessful!!" A= ' echo ${b%.*} ' if [ $a -gt 5 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 1" -m "$messagelog 2" else/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 1" -m "$messagelog" fi#!/bin/bashping -c 20 -i 0.1 222.240.x.x > test.txtb= ' cat test.txt|grep avg|awk ' {print $4} ' |awk -f/ ' {print $2} ' subject1= ' (info) 220.240.X.X Gateway Latency response time is $b ms " messagelog= "Gateway delay response monitoring success!!" Subject2= "(warn) 220.240.X.X Gateway Latency Response monitoring greater than 30ms" messagelog1= "Gateway latency response time is $b ms" a= "echo ${b% . *} ' if [ $a -gt 30 ];then/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [emAil protected] -t [email protected],[email protected],[email protected] -u "$subject 2" -m "$messagelog 1" else/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 1" -m "$messagelog" fi#!/bin/bashi=0j=0subject= "(info) Virtual ip-101.11 web status Monitoring" messagelog= "Virtual Ip-101.11 web status monitoring success!!" Subject1= "(critical) virtual Ip-101.11 web status monitoring messagelog1=" virtual ip-101.11 web status monitoring not successful!! " while [[ $i -le 10 ]]doi=$ ((${i}+1)) wget http://172.20.101.11/test.php b= ' cat test.php|grep "It is ok" |wc -l ' rm test.php -fif [ $b -ne 0 ];thenj=$ ((${j}+1)) elseexit 0fidoneif [ $j -ge 9 ];then/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[ email protected],[email protected] -u "$subject" -m "$messagelog" else/usr/local/ bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[ email protected],[email protected] -u "$subject 1" -m "$messagelog 1" fi#!/bin/ Bashb= ' Mysql -uroot -pxx -h 172.20.101.59 -e "show slave hosts" |grep " 3306 "|wc -l ' subject1=" (info)  MYSQL LVS status monitoring OK!! " messagelog= "Mysql lvs status monitoring normal!" Subject2= "(critical) mysql lvs status monitoring not normal!" messagelog1= "Mysql lvs status monitoring not normal!" if [ $b -eq 2 ];then/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] - Xp 1234565 -f [email protected] -t [email protected],[email protected] ,[email protected] -u "$subject 1" -m "$messagelog" else/usr/local/bin/sendemail - s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject 2" -m "$messagelog 1" fi#!/bin/bashb= ' mysql -uroot - Pxx -h 172.20.101.56 -e "show processlist;" | grep "Binlog dump" |wc -l ' subject1= "(info) mysql Master status monitoring OK!!" messagelog= "MySQL Master status monitoring ok!" Subject2= "(Error) mysql Master status monitoring not working properly!" messagelog1= "MySQL Master status monitoring is not working properly!" if [ $b -eq 2 ];then/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$ Subject1 " -m " $messagelog "else/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],tan[email protected] -u " $subject 2 " -m " $messagelog 1 "fi#!/bin/bashb= ' mysql -uroot -pxx -h 172.20.101.56 -e "show slave hosts" |grep "3306" |wc -l ' subject1= "(info) mysql from status monitoring ok!" Messagelog= "MySQL from status monitor normal!" Subject2= "(warn) mysql from status monitoring not normal!" Messagelog1= "MySQL from status monitoring not normal!" if [ $b -eq 2 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset= "UTF-8"  -XU [EMAIL&Nbsp;protected] -xp 1234565 -f [email protected] -t [email protected],[ email protected],[email protected] -u "$subject 1" -m "$messagelog" else/usr/local /bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[ email protected],[email protected] -u "$subject 2" -m "$messagelog 1" fi
This article is from the "Xiangjiang River Blowing Crazy" blog, please make sure to keep this source http://xjcf00.blog.51cto.com/10170403/1654869
Shell Monitoring Script 1