Sample Custom Check Script

 

/* Sample Custom Check

 

Upload this PHP script to your server to a directory that is accessable via a domain and supports php.

Add a custom check script type check and put the full url to the php script and include your selected key in the path.

e.g. http://mydomain.com/check/serverstatus.php?key=1234abc

 

Your custom check can run any tests you would like, the only requirement is that it returns a json string with three variables:

result
error_message
response_time

 

The result should be true if the test passes and false if the test fails.

The error_message should be the error messsage you would like to log and be send in the email alerts.

The response time measures how long it took the script/check to execute.

 

*/

 

// User Configured Variables

 

$key = "1234abc";

$disk_percentage_threshold = "80"; // When disk usage reaches this perctange an error will be returned.
$disk_path = "/"; // The path to check.

$load_threshold = "5";

 

if ($_GET['key'] == $key ) {

$error_message = "";
$pass = true;

// Start Response Time

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$start_time = $mtime;

// Disk Space Test

$disk_percentage_used = ((disk_free_space($disk_path) / disk_total_space($disk_path)))*100;

$disk_percentage_used = 100 - $disk_percentage_used;

if ($disk_percentage_used >= $disk_percentage_threshold) {

if($pass) {

$error_message = "Disk usage is at " . $disk_percentage_used . "%";

}

else {

$error_message = $error_message . ", Disk usage is at " . $disk_percentage_used . "%";

}

$pass = false;

}

// Load Test

$uptime = @exec('uptime');

preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$uptime,$avgs);

if ($avgs[1] >= $load_threshold) {

if($pass) {

$error_message = "Server Load is at ". $avgs[1];

}

else {

$error_message = $error_message . ", Server Load is at ". $avgs[1];

}

$pass = false;

}

// End Reponse Time

$mtime = microtime();

$mtime = explode(" ",$mtime);

$mtime = $mtime[1] + $mtime[0];

$end_time = $mtime;

$response_time = round(($end_time - $start_time), 3);

$results = array("result" => $pass, "error_message" =>$error_message, "response_time" => $response_time);

echo json_encode($results);

}

else {

echo "Access Denied";

}

 

?>

 

  • 60 Users Found This Useful
Was this answer helpful?

Related Articles

EULA

END USER LICENSE AGREEMENT This copy of ServerPing ("the Software Product") and...

System Requirements

Requirements You will need at least one Cent OS 6 (64 bit recommended) VPS/Dedicated server with...

Adding ServerPing to your Client Area template

You will need to provide a link to the SeverPing module from your client area. We recommend...

Terms and Conditions

Terms and Conditions   Agreement between user and serverping.net Welcome to serverping.net....

Recovering the MongoDB replicaset after a hard server reboot on 32bit systems

If one of your check servers crashes/was hard rebooted and it is running MongoDB you will most...