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 cpucheck.sh 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.

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

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. Hmm it appears like your site ate my first comment (it was super
    long) so I guess I’ll just sum it up what I wrote and say, I’m
    thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to everything.
    Do you have any suggestions for beginner blog writers?
    I’d certainly appreciate it.

 Leave a Reply

(required)

(required)

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>