#!/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) mysql Master /dev/sda1 hard disk space less than 95% "messagelog1=" MySQL master /dev/sda1 hard disk space usage is $Disk _used_rate1 " Subject2= "(Error) mysql Master /dev/sda1 hard disk space greater than 95%" messagelog2= "MySQL master /dev/sda1 hard disk space usage is $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) mysql Master /dev/sda2 hard disk space less than 95% " messagelog1= "MySQL Master /dev/sda2 hard disk space usage is $Disk _used_rate2 " subject2= "(Error) mysql main /dev/sda2 hard disk space is larger than 95% "messagelog2=" MySQL master /dev/sda2 hard disk space usage 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 "$ Messagelog1 "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 "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) mysql Master /dev/sdb1 hard disk space less than 95% "messagelog1=" MySQL master /dev/sdb1 Hard disk space usage is $Disk _used_rate3 "subject2=" (Error) mysql Master /dev/sdb1 hard disk space greater than 95% "messagelog2=" MySQL Master /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) mysql Master memory usage is less than 90% "messagelog1=" MySQL Master memory usage is $Memory _used_rate "subject2=" ( Error) mysql Master memory usage is greater than 90% "messagelog2=" MySQL Master 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 "$ Subject1 " -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#!/bin/bashb= ' uptime|awk ' {print $11} ' |awk -f, ' {print $1} ' subject1= ' (info) MySQL main cpu load is less than 2 "messagelog1=" MySQL main cpu load normal!! " Subject2= "(warn) mysql main cpu load is greater than 2 less than 8" messagelog2= "MySQL main cpu load busy!!" Subject3= "(Error) mysql main  CPU load greater than 8!!" messagelog3= "MySQL main cpu load overload!" A= ' echo ${b%.*} ' if [ $a -lt 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 1" elif [ $a -gt 2 -a $a -lt 8 ]; 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 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]ng.com,[email protected] -u "$subject 3" -m "$ Messagelog3 "fi
This article is from the "Xiangjiang River Blowing Crazy" blog, please make sure to keep this source http://xjcf00.blog.51cto.com/10170403/1654875
Shell Monitoring Script 4