technical skills grow

Responsive Ads Here

Wednesday, August 11, 2021

checkCPU.sh

 #!/bin/sh

processToSeek=$1
EMAIL="italerts@skymetweather.com"
MAX=90;
DURATION=60
cnt=0;
total=0;
i=0;
initTime=`date +%s`
process=$processToSeek

while [ $i -le 0 ]
do
        now=`date +%s`
        diff=`expr $now - $initTime`
        if [ $diff -ge $DURATION ]; then
                if [ $cnt -gt 0 ]; then
                        avg=`expr $total / $cnt`
                fi
                if [ "$avg" -ge "$MAX" ]; then
                        echo $avg
                        /root/it/skymet_mail_sender.sh "Monitoring Alert: $process average CPU usage = $avg in `hostname`" $EMAIL < /dev/null
                fi
                initTime=`date +%s`
                total=0
                cnt=0
        fi
 if [ -n "$processToSeek" ]
        then
                x=`top -b -n1|grep -w $processToSeek| head -1|awk '{print $9}'|awk -F \. '{print $1}'`
        else
                topProcess=`top -b -n1| head -8 | tail -1`
                x=`echo $topProcess |awk '{print $9}'|awk -F \. '{print $1}'`
                process=`echo $topProcess |awk '{print $12}'|awk -F \. '{print $1}'`
        fi
        cnt=`expr $cnt + 1`
        total=`expr $total + $x`
done



No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts