Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


CPU usage alarm
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

CPU usage alarm

Hello,

I have some gameservers and sometimes they need a high CPU usage, that's why I get a warning from my hoster. Of course I would like to avoid that and I'm asking myself if there is a script which checks the cpu usage and if it's above a fixed value, send me an email or something like that.

Thanks in advance for your help :)

Comments

  • klikliklikli Member
    edited June 2013

    lfd?

  • trexostrexos Member

    Thanks! Looks good but is it possible to automatically send emails when the cpu usage is to high?

  • gbshousegbshouse Member, Host Rep

    @trexos - Create free NewRelic account, install monitoring agent and configure the thresholds

  • perennateperennate Member, Host Rep

    You can do that with monit.

  • If all you want is an email when your cpu usage goes to high, you don't need to install anything fancy. You could use one of the many monitoring/alerting apps like the dudes above suggested, but <10 lines of bash combined with smtp-cli would do the job.

  • Lots of options mentioned. We'll throw our hat in the ring too - NodePing.com

  • asterisk14asterisk14 Member
    edited June 2013

    new relic or scale extreme is better, even send you a sms!

  • this script will automatically restart apache2 if the load gets above a value you set (change the value on the line check -gt 8 to whatever you need) and will also restart it if apache2 goes down.

    1. name script apache_check and upload the script to /bin, change permissions to 755
    2. run a cronjob (see script below) to check every x minutes (5 works well). To avoid receiving annoying emails every 5 minutes use the cron command:
      /bin/apache2checker >/dev/null 2>&1 instead of the one in the script notes.
    #!/bin/sh
    
    #*/5 * * * * /home/scripts/apache_check >> /home/scripts/apache_check.log
    # Bash script that checks apache:
    #   - Apache running or not, if needed start it up again
    #   - If server load is higher than 20, restart apache
    #
    #   Script to be ran as cronjob (every 5 minutes)
    #   */5 * * * * /path/to/apache_check >> /path/to/apache_check.log 
    
    echo "Apache checker running at " `date`
    run=`ps ax | grep /usr/sbin/apache2 | grep -v grep | cut -c1-5 | paste -s -`
    if [ "$run" ];
    then
    echo "Apache is running"
    else
    echo "Apache seems to be down, starting it up again"
    apache2ctl start
    fi 
    
    #!/bin/sh
    check=`uptime | sed 's/\./ /' | awk '{print $10}'`
    
    if [ $check -gt 8 ]
    then
            /etc/init.d/apache2 restart
    fi
    
Sign In or Register to comment.