Menu

Getting MRTG to show disk space

For a long time, I have been trying to get MRTG to show how much space there was left/used on a harddrive in my server. I have done this before, but that was on another server, running Windows 2003 server. Now I have changed to a HP Microserver N54L, and installed Debian on it.

After a lot time used on Google, a lot of failed attempts to configure SNMP to return info for the harddrives I want to monitor, and after breaking and fixing it all multiple times, I gave up… Until I had an idea…

I already got a script to extract a value from csv format in a file, and I am not sure why I haven’t got this idea before, but with a few modifications, that script could run a command to get info about the disk, calculate that into a percentage, and return that to MRTG.

And here it is, it is pretty simple. All it does is to run “df” and return the line defined by “$ARGV”, then take the total and used values, and calculate that into the percentage used on the drive.

I saved this in “/etc/mrtg/” with the filename “script_hdd.sh”, make sure to allow it to be executed.

And as you probably have noticed, it is way over the maximal 100% that should be possible, but we get to that in a second.

In the mrtg configuration, we define it like this, to make it execute the script and use the values from it.

As you see, after “/etc/mrtg/script_hdd.sh”, I have put “/dev/sdb1” in, this is the disk MRTG is going to keep track of.

To find out what you need to put in, run the “df” command, and look at the first part of the lines that is returned.

Remember that 5656.8% we got earlier? We are going to get that scaled down, so it fits within the 0-100% range, and we are doing that by setting YTicsFactor and Factor to 0.01. This will divide the returned values, so instead of 5656.8, it will be used as 56.568%, the reason for doing it like this, is to get a better resolution on the cart. If we just multiplied by 100 in the script to get the percentage, MRTG would only have 100 steps to show on the chart, which would make it less precise and also look bad.