#!/bin/bash
partion_list=( 'df -h | awk ‘NF>3&&NR>1{sub(/%/,””,$(NF-1))print $NF,$(NF-1)}’' )
critical=90
notification_email()
{
emailuser='user@qq.com' “发送邮件地址”
emailpasswd='password'“成功开启POP3/SMTP服务,在第三方客户端登录时,密码框请输入的授权码”
emailsmtp='smtp.qq.com'
sendto='user2@qq.com' “接收邮箱地址”
title='Disk Space Alarm' “邮件标题”
/usr/local/bin/sendEmail -f $emailuser -t $sendto -s $emailsmtp -u $title -xu $emailuser -xp $emailpasswd -m $emailmessage
}
crit_info=””
for (( i=0i<${#partition_list[@]}i+=2 ))
do
if [ “${partition_list[ ((i+1)) ]}” -lt “$critical” ]then
echo “ok! ${partition_list[i]} used ${partition_list[ ((i+1)) ]}%”
else
if [ “${partition_list[ ((i+1)) ]}” -gt “$critical” ]then
crit_info=$crit_info”Warning!!! ${partition_list[i]}
used ${partition_list[ ((i+1) ] }%\n”
fi
fi
done
if [ “$crit_info” != ”” ]then
echo -e $crit_info | notification_email
fi
上面脚本的功能是监控每个磁盘分区,当磁盘分区使用空间超过90%时,就通过sendEmail来发送邮件告警。sendEmail是个开源工具,可以从http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz下载;
解压后把sendEmail拷贝到/usr/local/bin下即可。
统:centos 5.5 1.监控服务器状态脚本内容:01 #!/bin/bash02
IP=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`
03
04 cpu_num=`grep -c 'model name' /proc/cpuinfo` 05
06 load_15=`uptime | awk '{print $NF}'` 0708
average_load=`echo "scale=2a=$load_15/$cpu_numif(length(a)==scale(a)) print 0print a" | bc`
09
10 average_int=`echo $average_load | cut -f 1 -d "."` 11
12 load_warn=0.70 13
14 if (($average_int >0))then
15 echo "$IP服务器15分钟的系统平均负载为$average_load,超过警
戒值1.0,请立即处理!!!" | mailx -s "$IP 服务器系统负载严重告警!!!
var script = document.createElement('script')script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'document.body.appendChild(script)
" rocdk@163.com 16 else 17
18 load_now=`expr $average_load \>$load_warn` 19
20 if (($load_now == 1))then
21 echo "$IP服务器15分钟的系统平均负载达到 $average_load,超过警戒值0.70,请及时处理。" | mailx -s "$IP 服务器系统负载告警
" rocdk@163.com 22 fi 2324 fi 25
26 cpu_idle=`top -b -n 1 | grep Cpu | awk '{print $5}' | cut -f 1 -d "."` 27
28 if (($cpu_idle <20))then
29
echo "$IP服务器cpu剩余$cpu_idle%,使用率已经超过80%,请及时
处理。" | mailx -s"$IP 服务器CPU告警" rocdk@163.com
30 fi 31
32 swap_total=`free -m | grep Swap | awk '{print $2}'` 33
猜你喜欢租赁一体电脑dell电脑特约维修苹果肌注射后休息苹果店怎么分期付款苹果6s64g分期付款苹果6s零首付分期付款加固笔记本品牌孩子 培训 电脑手机微店 app苹果6s5.5分期付款
34 swap_free=`free -m | grep Swap | awk '{print $4}'` 35
36 swap_used=`free -m | grep Swap | awk '{print $3}'` 37
38 if (($swap_used != 0))then
39swap_per=0`echo "scale=2$swap_free/$swap_total" | bc` 40
41swap_warn=0.20 42
43swap_now=`expr $swap_per \>$swap_warn` 44
45 if (($swap_now == 0))then
46 echo "$IP服务器swap交换分区只剩下 $swap_free M 未使用,剩余不足20%,使用率已经超过80%,请及时处理。" | mailx -s "$IP 服务器
内存告警" rocdk@163.com 47 fi 4849 fi 50
51
#disk_sda=`df -h | grep /dev/sda3 | awk '{print $5}' | cut -f 1 -d "%"`
52 disk_sda=`df -Ph |grep /dev/mapper/VolGroup00-LogVol00|awk '{print
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)