#!/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) web1 /dev/sda1 硬盘空间小于95%"messagelog1="web1 /dev/sda1 硬盘空间使用率为 $Disk_Used_Rate1 "subject2="(warn) web1 /dev/sda1 硬盘空间大于95%"messagelog2="web1 /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 admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject2" -m "$messagelog2"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) web1 /dev/sda2 硬盘空间小于95%"messagelog1="web1 /dev/sda2 硬盘空间使用率为 $Disk_Used_Rate2 "subject2="(warn) web1 /dev/sda2 硬盘空间大于95%"messagelog2="web1 /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 admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject2" -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) web1 /dev/sdb1 硬盘空间小于95%"messagelog1="web1 /dev/sdb1 硬盘空间使用率为 $Disk_Used_Rate3 "subject2="(warn) web1 /dev/sdb1 硬盘空间大于95%"messagelog2="web1 /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 admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject2" -m "$messagelog2"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 - $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) web1 内存使用率小于90%"messagelog1="web1 内存使用率为 $Memory_Used_Rate "subject2="(error) web1 内存使用率大于90%"messagelog2="web1 内存使用率为 $Memory_Used_Rate "if [ $free1 -lt 90 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject2" -m "$messagelog2"fi#!/bin/bashb=`uptime|awk '{print $11}'|awk -F, '{print $1}'`subject1="(info) web1 cpu负载小于2"messagelog1="web1 cpu负载正常!!"subject2="(warn) web1 cpu负载大于2小于8"messagelog2="web1 cpu负载忙!!"subject3="(error) web1 cpu负载大于8!!"messagelog3="web1 cpu负载超负荷!!"a=`echo ${b%.*}`if [ $a -lt 2 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog1"elif [ $a -gt 2 -a $a -lt 8 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject2" -m "$messagelog2"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject3" -m "$messagelog3"fi#!/bin/bashi=0j=0subject="(info) web1 web状态监控"messagelog="web1 web状态监控成功!!"subject1="(error) web1 web状态监控"messagelog1="web1 web状态监控不成功!!"while [[ $i -le 10 ]]doi=$((${i}+1))wget http://172.20.101.53/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 admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject" -m "$messagelog"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog1"fi#!/bin/bashhttping -c20 -g http://172.20.101.53 > test.txtb=`cat test.txt|grep avg|awk '{print $4}'|awk -F/ '{print $2}'`subject1="(info) web1 延迟响应时间为 $b ms"messagelog="web1 80 延迟响应监控成功!!"subject2="(warn) web1 延迟响应监控大于70ms"messagelog1="web1 80 延迟响应时间为 $b ms"a=`echo ${b%.*}`if [ $a -gt 70 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog2"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com,luoyunfei@huiyewang.com,tangwenming@huiyewang.com -u "$subject1" -m "$messagelog"fi