icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » Private Hosting » Load Alerts

Private Hosting Questions about VPS, dedicated servers and colocation.

Reply
 
LinkBack Thread Tools Search this Thread
Old March 23rd, 2006, 2:50 PM   #1 (permalink)
All Ur Base R Belong 2 Us
Excelling Contributor
 
mr_fern's Avatar
 
Joined in Feb 2005
Lives in Vegas & New York
824 posts
Gave thanks: 2
Thanked 6 times
Load Alerts

Well I decided to write myselfs some scripts to keep me informed of any issues with my servers. I figured I'd share them here.

The first is an Apache watchdog. It basically checks to see if Apache is running. If not, it attempts to restart it. It then sends a text message response regarding the success of the operation. I have tested everything but the restarting, so I won't post it yet.

But I did also create a basic Load alert system. It gets the current load of the system, and checks it against a configured value and then sends a text message if the load is higher than the configured value. It optionally also sends the current load value.

PHP Code:
<?php

/***********************************************************************
* Load Doctor v 0.1                                                    *
* (c) 2006 Pierre Fontenelle - http://brooklynrebel.com                *
*                                                                      *
* This program monitors your server's load and will alert you when     *
* the load is higher than a specified value. Alerts are sent via       *
* text messages to ensure prompt awareness.                            *
*                                                                      *
* Dependencies: uptime                                                 *
*                                                                      *
* Currently Supported Cell Companies:                                  *
*                                                                      *
* Sprint PCS (Sprint), Nextel (Nextel), AT&T (Cingular),               *
* Cingular (Cingular), T-Mobile (T-Mobile), Verizon (Verizon)          *
* Note: Parentheses stand for $service value                           *
*                                                                      *
* Valid Phone Number Formats:                                          *
* 1234567890, (123)456-7890, 123-456-7890, (123)456.7890, 123.456.7890 *                                                                       *                                                                      *
***********************************************************************/

// Enter Your Phone Number Here
// Valid Formats: (123)456-7890, 123-456-7890, (123)456.7890, 123.456.7890, 1234567890
$phone_number '123-456-7890';

// Enter Your Service Name Here
// Valids are listed at the top of file
$service 'Sprint';

// Subject
// Subject of Text Message
$subj 'Heartbeat Alert!';

// Max Load
// Set as a float.
// A decent load is CPUs * 1.00;
$load 0.00;

// Load Message: Sent when load is higher than desired value
$load_msg 'Your load has gone above the desired load value. ';

// Include Load:
// Set to 1 to include the current load value. 0 to omit it.
$include_load 1;

// Do Not Edit Below This Line
// Unless You Want To Of Course :)

if (isset($_SERVER['REMOTE_ADDR'])) // Make sure it's run through Command Line
    
die('This program is not intended to be run through a browser');

$uptime exec('uptime'); // get uptime data
$start strpos($uptime'load average:') + strlen('load average: ');
$loads substr($uptime$start);
list(
$current_load$five_minute_load$fifteen_minute_load) = explode(', '$loads);

$txtmsg_address get_message_addr($phone_number,$service); // prepares text message e-mail address

    
if ($current_load $load)
    {
        
$load_msg .= ($include_load) ? 'Current Load: '.$current_load ''//append current load
        
mail($txtmsg_address$subj$load_msg);
    }

function 
get_message_addr($number,$service) {

    
$number preg_replace('/[^0-9]/','',$number); // strip non digits
    
$service strtolower($service);
    
    
$services = array();
    
$services['sprint'] = 'messaging.sprintpcs.com';
    
$services['nextel'] = 'messaging.nextel.com';
    
$services['cingular'] = 'cingularME.com';
    
$services['t-mobile'] = 'tmomail.net';
    
$services['verizon'] = 'vtext.com';
    
    return 
$number     .'@'$services[$service];
}

?>
I had a weird issue occur at one point during testing. It stalled on one instance and shot the load up. It was due to the mail sending, however I think it was a result of the headers I was trying to send (which don't work for the email to sms conversion), so the headers were removed.

The script's intended to be ran as a minute interval cron job

Example Crontab Line:
* * * * * php -q /path/to/load_checker.php

Nothing complex, pretty simple script. If you decide to use it let me know, and let me know how things work out.

And if you have any suggestions, let me hear 'em

You can download a copy from the attached zip (The file header comments don't seem to show in the php code block
__________________
Nobody doing nothing
mr_fern is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:11 PM   #2 (permalink)
I'm Dope as Crack
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in Asheboro, NC
Hosted on Pass 7
13,036 posts
Gave thanks: 7
Thanked 29 times
And this is why you are in fact, the man. I'll use this tonight when I get home from work.
__________________

Last edited by David; March 23rd, 2006 at 4:13 PM.
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:18 PM   #3 (permalink)
Searcher
Surpass Staff
 
Kayla's Avatar
 
Joined in May 2003
Lives in Orlando
24,509 posts
Gave thanks: 936
Thanked 787 times
I like "heartbeat alert"..
Kayla is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:29 PM   #4 (permalink)
I'm Dope as Crack
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in Asheboro, NC
Hosted on Pass 7
13,036 posts
Gave thanks: 7
Thanked 29 times
I think I see next year's Ultimate Surpasser.
__________________
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:39 PM   #5 (permalink)
CTO, Surpass Hosting
Super #1
 
Emmanuel's Avatar
 
Joined in Apr 2003
Lives in Florida
1,811 posts
Gave thanks: 10
Thanked 131 times
Amazing, simply amazing

thanks for sharing your skills and knowledge
__________________
Emmanuel :: Surpass Hosting Network Admin
http://www.SurpassHosting.com
Emmanuel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:40 PM   #6 (permalink)
I'm Dope as Crack
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in Asheboro, NC
Hosted on Pass 7
13,036 posts
Gave thanks: 7
Thanked 29 times
No problem. I try but...oh you mean Fern. Yeah, thanks Fern.
__________________
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:41 PM   #7 (permalink)
Searcher
Surpass Staff
 
Kayla's Avatar
 
Joined in May 2003
Lives in Orlando
24,509 posts
Gave thanks: 936
Thanked 787 times
LOL
__________________
Follow Surpass on Twitter and Facebook
Check out interesting finds on the Surpass Blog
.... it's coming.


Kayla is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:42 PM   #8 (permalink)
CTO, Surpass Hosting
Super #1
 
Emmanuel's Avatar
 
Joined in Apr 2003
Lives in Florida
1,811 posts
Gave thanks: 10
Thanked 131 times
Quote:
Originally Posted by David
No problem. I try but...oh you mean Fern. Yeah, thanks Fern.
nice one head
__________________
Emmanuel :: Surpass Hosting Network Admin
http://www.SurpassHosting.com
Emmanuel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 23rd, 2006, 4:43 PM   #9 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Hosted on Gojira
8,032 posts
Gave thanks: 48
Thanked 129 times
Hmm that's damn nifty. From reading the code, this could actually be run by anyone, even non-dedicated customers, correct?
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On