LoadMonitoringScript
From WBITT's Cooker!
(Difference between revisions)
(Load average monitoring script) |
(→Load monitoring script) |
||
Line 10: | Line 10: | ||
HOSTNAME=$(hostname) | HOSTNAME=$(hostname) | ||
MAXLOAD=1 | MAXLOAD=1 | ||
- | MAILINGLIST="kamran@ | + | MAILINGLIST="kamran@example.com administrator@example.com" |
# ACTUALLOAD=$(uptime | awk '{print $11}' | cut -f 1) | # ACTUALLOAD=$(uptime | awk '{print $11}' | cut -f 1) | ||
# http://www.linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO-11.html | # http://www.linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO-11.html |
Current revision as of 06:56, 16 October 2010
Load monitoring script
[root@www ~]# cat /root/checkload.sh #!/bin/bash # Author: Muhammad Kamran Azeem # Created: Long ago # Last revised: 2010-01-24 HOSTNAME=$(hostname) MAXLOAD=1 MAILINGLIST="kamran@example.com administrator@example.com" # ACTUALLOAD=$(uptime | awk '{print $11}' | cut -f 1) # http://www.linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO-11.html # Or :- # uptime | grep -o 'load.*' | awk '{print $3}' | awk -F, '{print $1}' # Or :- # uptime | grep -o 'load.*' | awk '{print $3}' | cut -d, -f1 ACTUALLOAD=$(uptime | sed -e "s/.*load average: \(.*\...\), .*\..., .*\.../\1/" -e "s/ //g") if [ "$1" != "" ]; then ACTUALLOAD=$1 fi INTEGERLOAD=$(echo ${ACTUALLOAD} | cut -d. -f 1) if [ ${INTEGERLOAD} -lt ${MAXLOAD} ]; then uptime echo "5 minute load average is: ${ACTUALLOAD}, which is normal. (Below defined max value: ${MAXLOAD}.)" exit 0 fi echo "5 minute load avaerage is high: ${ACTUALLOAD}. Generating report of top 30 processes. (CPU and MEM.)" ## ps -eo "%C %p %u %U %c %x" |sort -r | head -n 10 > /tmp/load_report ps -eo pcpu,pmem,pid,ruser,user,comm,stat,time --sort -pcpu,-pmem | head -n 30 > /tmp/load_report.txt SUBJECT="High load: ${ACTUALLOAD} , on ${HOSTNAME}" cat /tmp/load_report.txt cat /tmp/load_report.txt | /bin/mail -s "${SUBJECT}" ${MAILINGLIST} exit 0 [root@www ~]#