#!/bin/bash
#安装邮件
rpm -q sendmail
if [ $? -ne 0 ];then
yum -y install sendmail
fi
rpm -q mutt
if [ $? -ne 0 ];then
yum -y install mutt
fi
systemctl restart sendmail
#安装邮件
rpm -q sendmail
if [ $? -ne 0 ];then
yum -y install sendmail
fi
rpm -q mutt
if [ $? -ne 0 ];then
yum -y install mutt
fi
systemctl restart sendmail
#设置变量
HOST=`hostname`
SYS=`uname -a`
DATE=`date "+%F %H:%M:%S"`
CPU=`cat /proc/cpuinfo |grep processor | wc -l`
ID=`vmstat | awk 'NR==3{print $15 }'`
WA=`vmstat | awk 'NR==3{print $16 }'`
LOAD=`w | awk 'NR==1{print $8}' |awk -F "," '{print $1}'`
DISK=`df |awk '{if(NR==7){print int($5)}}'`
FREE=`free -m | awk 'NR==2{print $4}'`
CACHE=`free -m | awk 'NR==2{print $7}'`
TCP=`netstat -atunlp`
IF=`iftop -i ens33 -P -Nn -L 100 -s 1 -t`
HOST=`hostname`
SYS=`uname -a`
DATE=`date "+%F %H:%M:%S"`
CPU=`cat /proc/cpuinfo |grep processor | wc -l`
ID=`vmstat | awk 'NR==3{print $15 }'`
WA=`vmstat | awk 'NR==3{print $16 }'`
LOAD=`w | awk 'NR==1{print $8}' |awk -F "," '{print $1}'`
DISK=`df |awk '{if(NR==7){print int($5)}}'`
FREE=`free -m | awk 'NR==2{print $4}'`
CACHE=`free -m | awk 'NR==2{print $7}'`
TCP=`netstat -atunlp`
IF=`iftop -i ens33 -P -Nn -L 100 -s 1 -t`
#cpu报警
if [ $CPU -eq 4 ];then
echo "wa=$WA and id=$ID cpu processor is ok"
else
echo "wa=$WA and id=$ID cpu processor have problem" |mutt -s "SYSTEM-memory" *********@163.com
fi
if [ $LOAD -gt 0.05 ];then
echo "CPU-LOAD is beyond the rate" |mutt -s "CPU-LOAD" ***********@163.com
else
echo "CPU-LOAD is ok"
fi
#磁盘报警
if [ $DISK -gt 80 ];then
echo "SYSTEM-DISK is beyond the 80%" |mutt -s "SYSTEM-DISK" ************@163.com
else
echo "SYSTEM-DISK is ok"
fi
#内存报警
memory=$(($FREE+$CACHE))
echo $memory
if [ $memory -lt 1000 ];then
echo "SYSTEM-memory less than 1000M " |mutt -s "SYSTEM-memory" *************@163.com
else
echo "SYSTEM-memory is ok"
fi
if [ $CPU -eq 4 ];then
echo "wa=$WA and id=$ID cpu processor is ok"
else
echo "wa=$WA and id=$ID cpu processor have problem" |mutt -s "SYSTEM-memory" *********@163.com
fi
if [ $LOAD -gt 0.05 ];then
echo "CPU-LOAD is beyond the rate" |mutt -s "CPU-LOAD" ***********@163.com
else
echo "CPU-LOAD is ok"
fi
#磁盘报警
if [ $DISK -gt 80 ];then
echo "SYSTEM-DISK is beyond the 80%" |mutt -s "SYSTEM-DISK" ************@163.com
else
echo "SYSTEM-DISK is ok"
fi
#内存报警
memory=$(($FREE+$CACHE))
echo $memory
if [ $memory -lt 1000 ];then
echo "SYSTEM-memory less than 1000M " |mutt -s "SYSTEM-memory" *************@163.com
else
echo "SYSTEM-memory is ok"
fi