Knowledge Base

Remotely Monitoring Free Disk Space on a PHP Enabled Web Server With IPCheck Server Monitor

Diese Seite steht leider noch nicht auf Deutsch zur Verfügung. Wir bitten um Ihr Verständnis!

This article explains how to monitor the free disk space on a remote web server that supports PHP scripts.

If your webserver is located outside of your LAN it is usually not possible to monitor the free disk space using SNMP or Windows System Sensors due to firewall and security restrictions.

Using the small PHP script below you can monitor the free diskspace on your remote web server using the "HTTP Content" sensor of IPCheck Server Monitor.

This sensor type requests a HTTP URL and parses the resulting HTML code for "[xxx]" and uses the "xxx" as the value for the sensor. So our script checks the free disk space and sends the results in a webpage for IPCheck to parse.

How to use this script:

  • copy this script into a folder of your webserver that is configured to run PHP scripts (e.g. /yourpath)
  • Edit the $username and $password constants below to your liking
  • create a "HTTP Content Sensor" in IPCheck Server Monitor
  • enter the following URL in the URL field
    http://yourserver/yourpath/ipcheckphpprobe.php?drive=c&user=myuser&pass=mypass
  • Enter values for the Constraints, e.g. the following values for percentages
    • Minimum: 20   (values below 20 will be shown as error)
    • Low: 40   (value below 40 will be shown as warning)
    • Maximum: 100  (anything up to 100 is ok)
    • High:    100  (anything up to 100 is ok)
  • Save the sensor

Notes:

  • you can monitor the free space on different drives by editing the "drive=" parameter
  • adding the parameter "&showpercent=1" will show the free space in percent
<?php
		/*
		* PHP Probe for IPCheck Server Monitor
		*
		* With this script you can monitor the diskspace of a php-enabled webserver with IPCheck Server Monitor
		* 
		* How to use this script:
		* - copy this script into a folder of your webserver that is configured to run PHP scripts (e.g. /scripts)
		* - Edit the $username and $password constants below to your liking
		* - create a "HTTP Content Sensor" in IPCheck Server Monitor
		* - enter the following URL in the URL field
		* http://yourserver/yourpath/ipcheckphpprobe.php?drive=c&user=myuser&pass=mypass
		* - Enter values for the Constraints, e.g. the following values for percentages
		* Minimum: 20 (values below 20 will be shown as error)
		* Low: 40 (value below 40 will be shown as warning)
		* Maximum: 100 (anything up to 100 is ok)
		* High: 100 (anything up to 100 is ok)
		* - save the sensor
		*
		* Notes:
		*
		* - you can monitor the free space on different drives by editing the "drive=" parameter
		* - adding the parameter "&showpercent=1" will show the free space in percent
		*
		* date: 2006-07-31
		* author: Dirk Paessler
		* requires: PHP 4.x
		*
		* (c) 2006 by Paessler AG, www.paessler.com
		*/
		/* login configuration */
		$username = 'myuser';
		$password = 'mypass';
		echo("<html><head><title>IPCheck PHP Probe</title></head><body>");
		/* check login */
		if ($username<>$user) { echo("Sorry, user '".$user."' does not exist here...");
		} else if ($password<>$pass) { echo("Sorry, your password is incorrect...");
		} else if (is_dir($drive.':')) { /* Get Disk Data */ $freespace = disk_free_space($drive.':'); $total_space = disk_total_space($drive.':'); $percentage_free = $freespace ? round($freespace / $total_space, 2) * 100 : 0; /* Show in HTML */ if ($showpercent=="1") { echo("Drive ".$drive.": has [".$percentage_free."] % free diskspace"); } else { echo("Drive $drive: has [".round($freespace/1024/1024)."] MB free diskspace"); } ;
		} else { echo("Sorry, drive ".$drive.": does not exist here...");
		}
		;
		echo("</body></html>");
		?>
		

By Category