Creating a send mail alert if load is high in server with w,pstree,mysqladmin results

Use the Below and code and save it in your root folder and add a cron to run in your server.

Replace [email protected] to your email-id and remove # before the email-id.

#!/bin/bash
#This script will send mail alert if load is high in server with w,pstree,mysqladmin results

#Enter The Email address
#email="[email protected]"

#Enter the Load Average
critical_load=15

current_load=`cat /proc/loadavg |awk '{print $2 }' |cut -d"." -f1 `

if [ $current_load -ge $critical_load=15 ]
then

cd /tmp
touch load.txt

#Enter the Text that you needs to dispaly on mail

echo "Please check the Server and reduce the Load" >> /tmp/load.txt
echo

echo  "LOAD STATUS RUN ON" `date` >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt

echo " W Results  " >> /tmp/load.txt

w >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt

echo "PSTREE Results" >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt

pstree -apu >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt
echo "MYSQLADMIN Results" >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt

mysqladmin proc >> /tmp/load.txt

echo "*******************" >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt

echo "NETSTAT RESULTS (FOR CHKING DDOS ATTACK..10 HIGH HTTP CONNECTIONS ) " >>/tmp/load.txt

echo >>/load.txt
netstat -plan |grep :80 | awk '{print $5}' |cut -d: -f1 |sort |uniq -c |sort -n |tail -10 >>/tmp/load.txt

echo "*******************" >> /tmp/load.txt
echo "*******************" >> /tmp/load.txt

mail -s "!!!Urgent HIGH LOAD Avg=$current_load in  $HOSTNAME " $email < /tmp/load.txt

>/tmp/load.txt

fi

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.