May 182013

This is a simple email alert for when your server process load reaches a defined threshold.

I wish I had retained the (StackExchange?) link I had found to give me the code below. Thank you to the original author. If you have a link to the source post for this code, please give credit in the comments below.

Save the code below as and execute via crontab every 15 minutes. It will email you at [email protected] a list of the top 10 cpu consuming running processes when the load average reaches 6.0 or higher.

SUBJECT="`hostname` server load is high"
TO=[email protected]
uptime > /tmp/load
if [ `uptime | awk '{ print$10 }' | cut -d. -f1` -gt 6 ];
echo "============================================" >> /tmp/load
`ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/load `
mail -s "$SUBJECT" $TO < /tmp/load

Adjust -gt 6 to be any minimum load number you prefer to receive the alert.

Remove “| head -10″ if you would prefer to see the entire list of running processes.

Helpful resources:

  One Response to “Simple Linux Load Email Alert”

  1. Great post. I was checking continuously this weblog
    and I am inspired! Very helpful info specifically the ultimate section :
    ) I care for such info much. I was looking for this certain information for a very long time.
    Thanks and good luck.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>