Results 1 to 10 of 10
-
03-29-2007, 05:33 PM #1Disabled
- Join Date
- Feb 2007
- Posts
- 164
Getting a notification when server load is greater than 5.0
Hello,
How can I get a notification to my email address when my server load is 5.0 or higher?
Please advise.
-
03-29-2007, 05:44 PM #2New Member
- Join Date
- Aug 2004
- Location
- Chicago
- Posts
- 2
You could try a script like this:
Code:#!/bin/sh ld=`uptime | awk -F, '{print $5}' | awk -F. '{print $1}'`; limit=5; if [ "$ld" -gt "$limit" ]; then echo "Server Load Exceeded"; fi exit 0
Code:| mail -s "Server Load Notification" email@whatever.com
-
03-29-2007, 05:57 PM #3Web Hosting Master
- Join Date
- Jun 2004
- Location
- Bay Area
- Posts
- 1,320
Yes and you'll get an email every minute in case of a problem
The best solution would be enabling SNMP on your box, and read that with a remote host. Because if server load is over 5.0, chances are that the box is too busy sending the notification email anyway
-
03-29-2007, 07:42 PM #4WHT Addict
- Join Date
- Jan 2003
- Posts
- 112
What is wrong with the load being over 5.0?
-
03-29-2007, 08:00 PM #5Web Hosting Master
- Join Date
- Mar 2001
- Location
- Connecticut, US
- Posts
- 779
Originally Posted by Xandrios
I'd proffer that a server load of 5 should not be too busy to process either.This space for let.
Inquire within.
-
03-29-2007, 09:41 PM #6Eternal Member
- Join Date
- Dec 2004
- Location
- New York, NY
- Posts
- 10,710
Originally Posted by Xandrios
-
03-29-2007, 10:37 PM #7Too smart for her own good.
- Join Date
- Feb 2004
- Location
- Your Screen
- Posts
- 3,999
Sending an e-mail when the load is over an arbitrary level is awfully simplistic.
It's not so much the load that is an issue, but rather the %CPU that is being consumed, or %CPU that is free.
What I recommend is the Monitor Server Load script from the PWS Scripts Club. The free version is okay, the paid version is awesome. (Paid version being a whopping $10) You can specify users, processes, and other particulars to ignore... great script, highly recommended. http://www.premierwebsitesolutions.com/scripts/monitor/
BaileyLet's Connect on Twitter! @thatsmsgeek2u || Fighting mediocrity one thread at a time.
-
03-29-2007, 10:40 PM #8Junior Guru Wannabe
- Join Date
- Sep 2001
- Location
- NC, USA
- Posts
- 39
Here's one I prepared earlier...
If there's a problem, it will only email once every hour.
Code:#!/bin/sh email='12345678@cingularme.com' host=`hostname` if [[ -f /tmp/nomail_loadcheck ]]; then emailsent=`find /tmp/nomail_loadcheck -mmin -60` if [ ${emailsent} ]; then exit fi rm -f /tmp/nomail_loadcheck fi loadavg=`cat /proc/loadavg` load=`echo $loadavg | awk -F" " '{print $2}' | awk -F"." '{print $1}'` if [ ${load} -gt 9 ]; then if [[ ! -f /tmp/nomail_loadcheck ]]; then touch /tmp/nomail_loadcheck cat ${loadavg} | /bin/mail -s "${host}: Load Critical" ${email} fi fi
-
03-29-2007, 10:46 PM #9Junior Guru Wannabe
- Join Date
- Sep 2001
- Location
- NC, USA
- Posts
- 39
Along the same lines as the above, here's one that will monitor the MySQL alert log and email you if any errors exist. It keeps track of the line numbers read so that alerts are sent only once per error.
Code:#!/bin/sh # host=`hostname` recipient='12345678@cingularme.com' flnm=chk_mysqllog tsp=`date '+%Y%m%d'` msglog=/tmp/${tsp}.${flnm} alert_log=/var/log/mysqld.log cd /tmp # If counter file doesn't exist, initialize it ... if [[ ! -f verified_alert_lines_cnt.lst ]] then echo 1 > verified_alert_lines_cnt.lst fi verified_alert_lines_cnt=`cat verified_alert_lines_cnt.lst` current_alert_lines_cnt=`cat $alert_log|wc -l` # If log has been cleared, re-initialize ... if [[ $current_alert_lines_cnt -lt $verified_alert_lines_cnt ]] then echo 1 > verified_alert_lines_cnt.lst verified_alert_lines_cnt=`cat verified_alert_lines_cnt.lst` fi # get new lines since last check ... (( verified_alert_lines_cnt = $verified_alert_lines_cnt + 1 )) tail +$verified_alert_lines_cnt $alert_log > verified_alert_lines.lst # grep new lines for errors ... grep "ERROR" verified_alert_lines.lst > alert_log_err.lst grep -i error verified_alert_lines.lst >> alert_log_err.lst # increment counter ... echo $current_alert_lines_cnt > verified_alert_lines_cnt.lst # notify dba on error alert_log_err_cnt=`cat alert_log_err.lst|wc -l` if (( $alert_log_err_cnt > 0 )); then /bin/mail -s "${host}: MySQL errors in log " "${recipient}" < alert_log_err.lst > /dev/null 2>&1 fi rm verified_alert_lines.lst alert_log_err.lst # if alert log is greater than 10000 rows then archive it if [[ $current_alert_lines_cnt -gt 10000 ]]; then echo archiving ${alert_log}... gzip -f1 ${alert_log} mv ${alert_log}.gz ${alert_log}-${tsp}.gz touch ${alert_log} echo 1 > verified_alert_lines_cnt.lst verified_alert_lines_cnt=`cat verified_alert_lines_cnt.lst` fi
-
03-30-2007, 03:58 AM #10Junior Guru Wannabe
- Join Date
- Apr 2005
- Posts
- 81
You could also check out monit
http://www.tildeslash.com/monit/
Which will do load and other system checks, mailing if something exceeds your defined thresholds.
It's not perfect but it does work.
Kev