Disk Utilisation Monitor

Objective: display graphical representations of the disk utilisation on my computer systems

Uses: C, SVG, HTML, Apache, CSS

This program is written in C and, when invoked as a CGI program through a web browser, checks the amount of disk space used on a pre-configured set of filesystems and then displays a set of icons with corresponding information. The icons are created in SVG and the files written to the default local Apache www directory. The program creates HTML on-the-fly that then refers to these SVG files using the <embed> tag. By adding an argument to the URL, you can specify that the page refreshes itself at regular intervals.

The first image shows a normal situation with all disk utilisation as satisfactory.

Disk utilisation icons

I then started to create a large file and took a screen shot when the utilisation threshold changed to warning (orange). You can easily create a large file using the following command:

cp /dev/zero bigfile

Disk utilisation icons

When the utilisation exceeded 90% and hit an alarm condition (red), I stopped the cp command to avoid crashing the system.

Disk utilisation icons


Program flowchart

The program reads a configuration file that contains the URL of the local web server, the filepath to the local www directory and then a series of filesystem mount points to be interrogated. The program uses the statvfsfunction to obtain the number of blocks, free blocks and block-size for each filesystem. It then creates a separate SVG file for each filesystem and then and then writes an HTML wrapper to stdout which is intercepted by Apache and served to the browser. Each SVG file and the HTML wrapper share a CSS file where the various fonts, colours and styles can be defined. The program uses six CSS classes to identify the various disk utilisations: <50%, >50%, >60%, >70%, >80% and >90%. You can change the colour of each class to suit your requirements.

The program flowchart and the files and directories used by the program are shown here.

Download The Program

Follow the commands below to download, compile and configure the utility. A standard installation of Apache is a pre-requisite with default directory names.

Step 1

Download the C program and compile it:

cd ~

sudo wget http://www.noveldevices.co.uk/rpdl/drive.c

sudo gcc drive.c -o /usr/lib/cgi-bin/drive

Step 2

Download the sample CSS file and put it in its correct directory. You do not need to make any changes to the CSS file:

sudo wget http://www.noveldevices.co.uk/rpdl/driveinfo.css -O /var/www/driveinfo.css

Step 3

Download the sample configuration file and put it in its correct directory:

sudo wget http://www.noveldevices.co.uk/rpdl/driveinfo.ini -O /usr/lib/cgi-bin/driveinfo.ini

The records in the driveinfo.ini file need to be entered as follows:

  1. URL to the web server that will serve the SVG pages from its www directory: e.g.
  2. the Linux directory name that is Apache's www directory with a trailing /: e.g. /var/www/
  3. the name of a local or mounted remote filesystem whose free space is to be displayed followed, optionally, by a label: e.g. /mnt/my-PC Desktop PC
  4. additional local or mounted remote filesystems...
  5. an end tag: *END

Step 4

When everything is complete, you can try invoking the program in a browser using the following URL: