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
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018