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.
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
When the utilisation exceeded 90% and hit an alarm condition (red), I stopped the cp command to avoid crashing the system.
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.
Download the C program and compile it:
sudo wget http://www.noveldevices.co.uk/rpdl/drive.c
sudo gcc drive.c -o /usr/lib/cgi-bin/drive
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
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:
- URL to the web server that will serve the SVG pages from its www directory: e.g. http://10.34.220.163
- the Linux directory name that is Apache's www directory with a trailing /: e.g. /var/www/
- 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
- additional local or mounted remote filesystems...
- an end tag: *END
When everything is complete, you can try invoking the program in a browser using the following URL: