Results 1 to 10 of 10
  1. #1

    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.

  2. #2
    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
    set limit= to whatever you want, then create a cronjob to run the script every minute and add
    Code:
     | mail -s "Server Load Notification" email@whatever.com
    to the end of the cronjob line. I believe that should work. I'm sure there's easier ways, but it's workable

  3. #3
    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

  4. #4
    What is wrong with the load being over 5.0?

  5. #5
    Join Date
    Mar 2001
    Location
    Connecticut, US
    Posts
    779
    Quote Originally Posted by Xandrios
    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
    If it is too busy to send a simple email, doncha think it might also be too busy to process an SNMP request?


    I'd proffer that a server load of 5 should not be too busy to process either.
    This space for let.
    Inquire within.

  6. #6
    Join Date
    Dec 2004
    Location
    New York, NY
    Posts
    10,710
    Quote Originally Posted by Xandrios
    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
    Depends on the box. 5.0 isn't so bad for a dual/quad core/processor machine.

  7. #7
    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/

    Bailey
    Let's Connect on Twitter! @thatsmsgeek2u || Fighting mediocrity one thread at a time.

  8. #8
    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

  9. #9
    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

  10. #10
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •