Educational ICT Virtualisation Specialist

Twitter LinkedIn E-mail
Precedence Technologies Ltd
Technology House, 36a Union Lane
Cambridge, CB4 1QB, United Kingdom
T: +44 (0)1223 359900
E: sales@precedence.co.uk
DiskUsageReports

Jump To: Support > KB > Software > DiskUsageReports

Creating HTML disk usage reports with NetManager

This is a quick example of how you may automate disk usage reports and allow easy centralised access. It could be significantly improved.

  1. Edit /etc/netmanager/netman.conf and add the following:
    php_maxmemory="512M"
    php_maxuploadsize="256M"
    
  2. Run /usr/libexec/build/php
  3. Download Disk Usage Reports as a zip file. On NetManager you can type:
    ftp https://github.com/amekkawi/diskusagereports/archive/refs/heads/master.zip
    
  4. The zip file contains a folder called diskusagereports-master. Copy this to \\netmanager\webpages and rename to diskusage. On NetManager you can type:
    unzip -d ~www master.zip
    mv ~www/diskusagereports-master ~www/diskusage
    chown -R www ~www/diskusage
    
  5. Check the basic installation is OK by going to http://netmanager/diskusage/ (you will see Error: The settings file for the report was not found, but this can be ignored)
  6. Find a location to put scripts and utilities which can be run to generate the reports. For a single Windows fileserver, this can probably just be C:\diskusage, but you may want to use a central ITSupport share or such like. This will be referred to as the script location below.
  7. Copy \\netmanager\webpages\diskusage\scripts\find.exe into the script location
  8. Download cURL for Windows using one of the links at the cURL website. The latest win64 version can always be found here
  9. Open the cURL zip file and look for the bin folder. In there, you will see curl.exe. Copy this to the script location
  10. Create a batch file call genreport.bat in the script location containing the following. Alter the location to the top level that you want to analyse (in this example it is G:\Shared):
    set SUBMIT=http://netmanager/diskusage/submit.php
    %0\..find.exe -ds / G:\Shared > %TMP%\files.txt
    %0\..curl.exe -F "filelist=@%TMP%\files.txt" %SUBMIT%
    %TMP%\files.txt
  11. If you wish to run reports on multiple servers (or for different locations on a single server), you can specify a report name by adding -F name=REPORTNAME to the curl.exe line. The example below generates two different reports:
    set SUBMIT=http://netmanager/diskusage/submit.php
    %0\..\find.exe -ds / G:\Shared > %TMP%\files.txt
    %0\..\curl.exe -F "filelist=@%TMP%\files.txt" -F name=Shared %SUBMIT%
    %0\..\find.exe -ds / G:\Staff > %TMP%\files.txt
    %0\..\curl.exe -F "filelist=@%TMP%\files.txt" -F name=Staff %SUBMIT%
    del %TMP%\files.txt
  12. Create a file called \\netmanager\webpages\diskusage\submit.php (or ~www/diskusage/submit.php on NetManager) containing:
    <?php
    if (!isset($_FILES['filelist'])) {
            echo "No file given";
            exit;
    }
    if (!is_uploaded_file($_FILES['filelist']['tmp_name'])) {
            echo "File is not uploaded";
            exit;
    }
    set_time_limit(0);

    $d = dirname($_SERVER['SCRIPT_FILENAME']);
    $cmd = "/usr/pkg/bin/php $d/scripts/process.php -mt 13107200 $d/data";
    if (!empty($_REQUEST['name'])) {
            $n = trim(basename($_REQUEST['name']));
            $cmd .= "/$n";
    }
    $cmd .= " ".$_FILES['filelist']['tmp_name'];

    exec($cmd, $output);
    foreach ($output as $l) {
            echo htmlentities($l)."<br/>\r\n";
    }
  13. Create a file ~www/diskusage/.htaccess on NetManager containing the following. Alter the Allow from line so it has a space-separated list of IP addresses which can view reports without having to log in (i.e. all fileservers, plus IT staff's PCs with statically configured IP addresses). Alter the Require user line to have a space-separated list of users who can view reports:
    Order Deny,Allow
    Deny from all
    # Add the IP addresses or ranges of the computers that can view reports without logging in
    Allow from 10.0.0.0/24
    Satisfy Any
    AuthType Basic
    AuthName "Disk Usage reports"
    AuthExternal passwd
    AuthBasicProvider external
    # Add the users who can access reports from any computer
    Require user username1 username2
    <Files "submit.php">
    Deny from all
    # Add the IP addresses of the servers that will be submitting reports below
    Allow from 10.0.0.5
    </Files>

  14. Run genreport.bat from the script location and then test it works at http://netmanager/diskusage/. If you have specified a report name with the -F name=REPORTNAME option above, then you will need to go to http://netmanager/diskusage/?REPORTNAME (case-sensitive)
  15. Set up scheduled tasks to run the batch file(s) on each server. Weekly is probably sufficient
© Copyright Precedence Technologies 1999-2025
Page last modified on January 29, 2025, at 01:06 PM by sborrill