shell监控脚本1

#!/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/sda1
Disk_Used_Rate1=$(df -h | grep $Location | awk ‘{print $5}‘)
free1=`echo $Disk_Used_Rate1|awk -F% ‘{print $1}‘`
subject1="(info) monitor /dev/sda1 硬盘空间小于95%"
messagelog1="monitor /dev/sda1 硬盘空间使用率为 $Disk_Used_Rate1 "
subject2="(warn) monitor /dev/sda1 硬盘空间大于95%"
messagelog2="monitor /dev/sda1 硬盘空间使用率为 $Disk_Used_Rate1 "
if [ $free1 -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 "$subject1" -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 "$subject2" -m "$messagelog2"
fi

Location=/dev/sda2
Disk_Used_Rate2=$(df -h | grep $Location | awk ‘{print $5}‘)
echo $Disk_Used_Rate2
free1=`echo $Disk_Used_Rate2|awk -F% ‘{print $1}‘`
subject1="(info) monitor /dev/sda2 硬盘空间小于95%"
messagelog1="monitor /dev/sda2 硬盘空间使用率为 $Disk_Used_Rate2 "
subject2="(warn) monitor /dev/sda2 硬盘空间大于95%"
messagelog2="monitor /dev/sda2 硬盘空间使用率为 $Disk_Used_Rate2 "
if [ $free1 -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 "$subject1" -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 mo
[email protected],[email protected],[email protected] -u "$subject2" -m "$messagelog2"
fi

Location=/dev/sdb1
Disk_Used_Rate3=$(df -h | grep $Location | awk ‘{print $5}‘)
echo $Disk_Used_Rate3
free1=`echo $Disk_Used_Rate3|awk -F% ‘{print $1}‘`
subject1="(info) monitor /dev/sdb1 硬盘空间小于95%"
messagelog1="monitor /dev/sdb1 硬盘空间使用率为 $Disk_Used_Rate3 "
subject2="(warn) monitor /dev/sdb1 硬盘空间大于95%"
messagelog2="monitor /dev/sdb1 硬盘空间使用率为 $Disk_Used_Rate3 "
if [ $free1 -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 "$subject1" -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 "$subject2" -m "$messagelog2"
fi
 
#memory_used_rate
LoadMemory=$(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 - $Free1 - $Free2 - $Free3`
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 内存使用率小于90%"
messagelog1="monitor 内存使用率为 $Memory_Used_Rate "
subject2="(error) monitor 内存使用率大于90%"
messagelog2="monitor 内存使用率为 $Memory_Used_Rate "
if [ $free1 -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 "$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 "$subject2" -m "$messagelog2"
fi
#!/bin/bash
ping -c 20 -i 0.1 222.240.205.161 > test.txt
b=`cat test.txt|grep "packet loss"|awk ‘{print $6}‘|awk -F% ‘{print $1}‘`
subject1="(info) 220.240.X.X 网关丢包率小于5%"
messagelog="网关丢包率监控成功!!"
subject2="(warn) 220.240.X.X 网关丢包率大于5%"
messagelog1="网关丢包率监控不成功!!"
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 "$subject1" -m "$messagelog2"
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 "$subject1" -m "$messagelog"
fi
#!/bin/bash
ping -c 20 -i 0.1 222.240.X.X > test.txt
b=`cat test.txt|grep avg|awk ‘{print $4}‘|awk -F/ ‘{print $2}‘`
subject1="(info) 220.240.X.X 网关延迟响应时间为 $b ms"
messagelog="网关延迟响应监控成功!!"
subject2="(warn) 220.240.X.X 网关延迟响应监控大于30ms"
messagelog1="网关延迟响应时间为 $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 "$subject2" -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 "$subject1" -m "$messagelog"
fi
#!/bin/bash
i=0
j=0
subject="(info) 虚拟ip-101.11 web状态监控"
messagelog="虚拟ip-101.11 web状态监控成功!!"
subject1="(critical) 虚拟ip-101.11 web状态监控"
messagelog1="虚拟ip-101.11 web状态监控不成功!!"
while [[ $i -le 10 ]]
do
i=$((${i}+1))
wget http://172.20.101.11/test.php 
b=`cat test.php|grep "it is ok"|wc -l`
rm test.php -f
if [ $b -ne 0 ];
then
j=$((${j}+1))
else
exit 0
fi
done
if [ $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 "$subject1" -m "$messagelog1"
fi
#!/bin/bash
b=`mysql -uroot -pXX -h 172.20.101.59 -e"show slave hosts"|grep "3306"|wc -l`
subject1="(info) mysql lvs状态监控正常!!"
messagelog="mysql lvs状态监控正常!!"
subject2="(critical) mysql lvs状态监控不正常!!"
messagelog1="mysql lvs状态监控不正常!!"
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],[email protected] -u "$subject2" -m "$messagelog1"
fi
#!/bin/bash
b=`mysql -uroot -pXX -h 172.20.101.56 -e"show processlist;"|grep "Binlog Dump"|wc -l`
subject1="(info) mysql主状态监控正常!!"
messagelog="mysql主状态监控正常!!"
subject2="(error) mysql主状态监控不正常!!"
messagelog1="mysql主状态监控不正常!!"
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],[email protected] -u "$subject2" -m "$messagelog1"
fi
#!/bin/bash
b=`mysql -uroot -pXX -h 172.20.101.56 -e"show slave hosts"|grep "3306"|wc -l`
subject1="(info) mysql从状态监控正常!!"
messagelog="mysql从状态监控正常!!"
subject2="(warn) mysql从状态监控不正常!!"
messagelog1="mysql从状态监控不正常!!"
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],[email protected] -u "$subject2" -m "$messagelog1"
fi
时间: 2024-08-01 01:06:44

shell监控脚本1的相关文章

shell监控脚本

shell脚本监控网站并实现邮件.短信报警 shell进程监控脚本(发送邮件报警) Shell脚本监控服务器在线状态和邮件报警的方法 如果是139邮箱还可免费手机短信通知.注:通过系统直接发送mail容易被拦截,可使用mail连接第三方smtp发送邮件.

shell监控脚本----硬盘空间和内存

实时监控本机内存和硬盘剩余空间,剩余内存小于 500M.根分区剩余空间小于 1000M 时发送报警邮件给root 管理员 1 写脚本[[email protected] ~]# vim jiankong.sh #!/bin/bash#此脚本中数字单位是kb,可根据自己需要调整数字大小#此脚本整体定义函数放入后台执行jiankong () {disksize=$(df /| awk '/\//{print$4}')memsize=$(free | awk '/Mem/{print$4}')whil

shell监控脚本2

#!/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/sda1 Disk_Used_Rate1=$(df -h | grep $Location | awk '{print $5}') free1=`echo $Dis

shell监控脚本3

#!/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/sda1 Disk_Used_Rate1=$(df -h | grep $Location | awk '{print $5}') free1=`echo $Dis

shell监控脚本,不考虑多用户情况

#!/bin/bash CheckProcess() { if [ "$1" = "" ]; then return 1 fi PROCESS_NUM=`ps -ef | grep "$1" | grep -v "grep" | wc -l` if [ $PROCESS_NUM -eq 1 ]; then return 0 else return 1 fi } while [ 1 ] ; do #输入进程名 echo &quo

shell监控脚本4

#!/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/sda1 Disk_Used_Rate1=$(df -h | grep $Location | awk '{print $5}') free1=`echo $Dis

shell监控进程状态,自启动

shell 监控脚本,通过会while true 实现,没有使用crontab #!/bin/bash source /etc/profile appname=aurora-gateway-provider-1.3.1_build2.jar #[jps 显示的 进程名称] app_path=/opt/workspace/aurora-gateway/ #[app_script 的上层目录,和启动方式配合,如 aurora-gateway的启动方式是 sh sbin/app.sh start] a

shell迷你版监控脚本

写了一个shell版mini监控脚本,纯属跟大家分享学习下,有兴趣学习shell的可以看下.(*_*) 总共3个脚本文件service.sh, daemon.sh ,tcp.sh 实现了一些基本功能:端口监控,存活监控,掉线邮件报警,重新上线邮件通知 将3个文件放在同个目录下 设置:在tcp.sh中可以设置邮件通知地址,与邮件通频率次数 运行: ./service.sh start 主要文件代码如下: tcp.sh文件 #!/bin/bash LANG=C #邮件地址设置 fromaddress

Shell开发MySQL主从监控脚本

监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员. 1)开发一个守护进程脚本每30秒实现检测一次. 2)如果同步出现如下错误号(1158,1159,1008,1007,1062),则跳过错误. 阶段3:3)如果IO和SQL线程出现异常,则通知邮件给管理员 使用数组技术实现上述脚本(获取主从判断及错误号部分) 主从监控脚本如下: #!/bin/bash CODE=( 1158 1159 1008 1007 1062 2003 ) fun_Base(){ #1.定义变量 #1.1