主机IO过高邮件告警其进程

主机IO过高邮件告警其进程

Scroll Down
#!bin/bash

set -e
Date=`date "+%Y_%m_%d %H:%M:%S"`

iotop -b -d 0.5 -n 5 -oPk|grep -v COMMAND|grep -v "Total DISK WRITE"|grep -v "Actual DISK WRITE" |sort -k 10 -g -r |head -n 10 > /home/tempfile
IP=$(ifconfig ens192 | awk -F "[ :]+" '/inet /{print $3}' )

if [ -s /home/tempfile ]; then

i=0

for j in $( cat /home/tempfile|head -n 1|awk '{print $10}' )
do
if [ $j \> 70.00 ];then
i=$(($i+1))
fi
done

if [ $i -gt 0 ];then
mail -s "HOST:$IP IO读写速率当前值" luwei@axhome.com.cn < /home/tempfile
mail -s "HOST:$IP IO读写速率当前值" yangzuoqiang@axhome.com.cn < /home/tempfile
echo "$Date :邮件已发" >> /home/check_io_scripts_record
else 
echo "$Date :单进程io正常" >> /home/check_io_scripts_record
fi

else

echo "$Date :当前时间开始 0.5秒间隔取值5次无有效IO数据" >> /home/check_io_scripts_record

fi