ChillNet - The Power of Simplicity - Development, Hosting, Bulk SMS and Fax2email made easy!

Load Average notification script PHP PDF Print E-mail
Monday, 06 June 2011 15:09

For those out there looking for a quick way to check the load avarage of your server via a command line PHP script, and give you some output only if the load is higher than X, look at the following it might help.

In a terminal window, type the following:

vi checkLoadAvg.php

Now add the following lines to that file:

 
#!/usr/bin/php -f 
<?php  
$loadWarning = 3; 
$load = sys_getloadavg(); 
$hostname = trim(shell_exec('hostname')); 
if($load[0] > $loadWarning)
{ 
echo "Busy - Load Average detected on {$hostname} - Current Load: {$load[0]} (15min Avg: {$load[2]}) \n\n"; 
echo shell_exec('top -bn 1'); 
} ?> 

Save and quit ':wq', then add executable privileges to the file

chmod +x checkLoadAvg.php

Last Updated ( Tuesday, 07 June 2011 06:37 )
 

Signup For Fax2Email

 
Get your free Fax2Email number
 
Email Address:
Contact Name:
Contact Number:
 
 

Random Products

R7 500.00

R12 500.00

Banner