New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


How can I remotely monitor the free disk space on an PHP enabled server with PRTG?

Votes:

0

Your Vote:

Up

Down

I would like to monitor the free disk space of my web server. It supports PHP. Can I use a PHP script to remotely monitor my server's parameters?

custom-script-exe disk-free http-content-sensor http-sensor linux php prtg script web-application web-server

Created on Feb 17, 2010 4:05:27 PM by  Daniel Zobel [Paessler Support]

Last change on Mar 16, 2015 5:07:37 PM by  Martina Wittmann [Paessler Support]



1 Reply

Accepted Answer

Votes:

0

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 7 or later

Remotely Monitoring Free Disk Space on an PHP Enabled Web Server

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 "PHP probe" below you can monitor the free diskspace on your remote web server using the "HTTP Content" sensor of PRTG Network Monitor.

This sensor type requests a HTTP URL and parses the resulting HTML code for "[xx]" and uses the "xx" as the value for the sensor. So our script checks the free disk space and sends the results in a web page for PRTG to parse. See Using the HTTP Content Sensor for a general introduction.

How to Use The Script

  • Copy the script below into a folder of your web server that is configured to run PHP scripts (e.g. /yourpath)
  • Edit the $username and $password constants below to your liking
  • Test the script by calling it in a web browser, e.g.
http://yourserver/yourpath/prtgphpprobe.php?drive=C:&user=myuser&pass=mypass
  • In the URL, replace the "drive" value C: with the according value:
Server TypeWhat to enterExample
Windows serverThe drive letter you want to monitor, followed by a colonC:
Linux serverThe path you want to monitor, for example / for root/etc
  • In the URL, replace myuser and mypass by the values you entered in the script.
  • As soon as the script returns the desired values, you can add the URL as a sensor in PRTG.

Steps to Take in PRTG

  • In the PRTG web interface, create a new device with the IP address or DNS name of your web server running the PHP script.
  • Create a HTTP Content sensor (from section "Web Servers") on this device:
  • Enter the Script Url from above e.g.
http://yourserver/yourpath/prtgphpprobe.php?drive=C:&user=myuser&pass=mypass
  • For the number of channels, enter "2", as the script returns the free disk space in two different ways: percent and total. Each value will be displayed in a separate channel of the sensor (Value 1 and Value 2).
  • Click on Save and open the sensor's settings again.
  • In the Channels tab, you can now enter the according Unit labels (% for channel Value 1; usually MB for channel Value 2).
  • In the Notifications tab, you can add Threshold Triggers to be notified when the disk free values are above or below a certain value. See user manual section Notifications for more details.

Remarks

  • If the script returns errors, make sure you have sufficient rights on the web server.
  • Of course, you can also monitor other parameters of your web server by using other PHP functions
  • You can add several HTTP Content sensors in PRTG in order to monitor more than one drive or path.

The Script

<?php
/*
* PHP Probe for PRTG Network Monitor (http://www.paessler.com/prtg)
* With this script you can monitor the diskspace of a php-enabled webserver with PRTG Network Monitor
*                  
*    - Copy the script below into a folder of your web server that is configured to run PHP scripts (e.g. /yourpath)
*    - Edit the $username and $password constants below to your liking
*    - Test the script by calling it in a web browser, e.g. 
*
*		http://yourserver/yourpath/prtgphpprobe.php?drive=C:&user=myuser&pass=mypass
*
*    - In the URL, replace the "drive" value C: with the according value: 
*
*		Windows server	The drive letter you want to monitor, followed by a colon
*		Linux server	The path you want to monitor, for example / for root
*
*    - In the URL, replace myuser and mypass by the values you entered in the script.
*    - As soon as the script returns the desired values, you can add it as a HTTP Content sensor in PRTG. 
*
*	 - See /en/topic/1023 for more details.
*
* date: 2010-02-18
* author: Daniel Zobel
* requires: PHP 4.x
*
* (c) 2010 by Paessler AG, www.paessler.com
*/

/* ***************************************************************************************
   L O G I N   C O N F I G U R A T I O N
*************************************************************************************** */
$username    = 'myuser';
$password    = 'mypass';

/* No need to change parameters after this line 
*************************************************************************************** */
echo("<html><head><title>PRTG Network Monitor PHP Probe</title></head><body>");

/* Catch Parameters From URL */
   $user = $HTTP_GET_VARS["user"];
   $pass = $HTTP_GET_VARS["pass"];
   $drive = $HTTP_GET_VARS["drive"];

/* 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 */
        echo("<b>".$drive."</b> has [".$percentage_free."] % free diskspace<br>");
        echo("<b>".$drive."</b> has [".round($freespace/1024/1024)."] MB free diskspace<br>");
   } else {
        echo("Sorry, <b>".$drive."</b> does not exist here...");
   };
echo("</body></html>");
?>

More

For another example of using a PHP script, please see Using phpSysInfo to Monitor the System Health of a PHP Web Server With PRTG

Created on Feb 17, 2010 4:28:50 PM by  Daniel Zobel [Paessler Support]

Last change on May 28, 2014 1:12:56 PM by  Gerald Schoch [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.