Diskspacemonitor Hack

March 14, 2009

Diskspacemonitor is a nice feature and something I try to remember to activate on all servers I manage, but unfortunately it’s missing the ability to choose which volumes you actually want to monitor. So whenever someone sticks a CD in or mounts a disc image, your helpdesk inbox will be flooded with messages, every 10 seconds.

I looked into it and could’t find any hidden variable to change this, but being a nicely written shell script, diskspacemonitor is easy to customize. The more academic way to do this would perhaps be through the various .local files, but I really wanted this to be “central” so I decided to modify diskspacemonitor directly.

We start by telling the system what we actually want:

$ sudo nano /etc/diskspacemonitor/diskspacemonitor.conf

… and define a variable, like “volumes”, which contains a regex of all the mount points you want to monitor, for instance, to only monitor the boot volume (keeping in mind that we’re filtering df -l output):

volumes='/$'

You must use alternation to define several volumes, like:

volumes='/$|data$'

Now add the checking to the diskspacemonitor script:

sudo nano +66 -B /usr/sbin/diskspacemonitor

Modify that line to something like:

df -l | awk '/^\/dev/{print $1}' | grep -E "${volumes}"

And that’s it!

When (if) Apple decides to fix this, I hope they also move it launchd, since this whole thing is totally reliant on cron right now.