This is a small shell script to monitor CPU usage. IF the cpu usage is more than 75% then send an e-mail to respective teams.

	
#!/bin/bash
#Author: Surendra Kumar Anne
#Purpose: To monitor the CPU usage
#Date:2012-04-13
SUBJECT="WARNING CPU USAGE HIGH"
TO=yourteam@companiesemailcom
MESSAGE=/tmp/messages
echo "#######################" > $MESSAGE

echo "CPU statistics as follows.." >> $MESSAGE

mpstat >> $MESSAGE
echo "#######################" >> $MESSAGE
CPU_USAGE=$(top -b -n1 | awk '/^Cpu/ {print $2}' | cut -d. -f1)
[ $CPU_USAGE -gt 75 ] && mail -s "$SUBJECT" "$TO" < $MESSAGE

 

Once the above script is written and given execute permissions keep this script in crontab which runs for every 1min or 5mins.

	0-59 * * * *  bash /pathtoscript.sh
The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.