Articles January 7, 2005 at 8:40 pm

Configuring/Implementing diskspacemonitor on OS X Server

Learn more about configuring diskspacemonitor in the second of our series of articles.

The following information is based off of OS X Server 10.3.5


OS X Server comes with a utility called diskspacemonitor. This is a configurable, cron-activated commandline tool that resides in /usr/sbin/diskspacemonitor. It is designed to periodically monitor the amount of free space on disks and execute pre-configured actions when thresholds are reached.

This tutorial will walk you through the simple steps of configuring and implementing this utility. Please read the Introduction to diskspacemonitor on OS X Server before reading this tutorial.

diskspacemonitor and Cron

Before enabling diskspacemonitor, you should read up on cron and /etc/crontab (check the man pages for cron and crontab). Diskspacemonitor uses cron to launch itself but it does not edit the /etc/crontab file, instead it uses root’s crontab file.

Step #1: Before enabling diskspacemonitor you should check whether or not the root user has a crontab file.

[X:/] admin$ sudo crontab -l
crontab: no crontab for root

The example above shows that there was no crontab for root. If your results show a crontab that was already setup then back it up. Disabling diskspacemonitor may delete the entire root crontab file (losing any settings you already had). This was the case when testing with OS X Server 10.3.5. It was not the case on another box running OS X Server 10.3.3.

Step #1a: Backup the current crontab for root (if exists).

[X:/] admin$ sudo crontab -l > /path/to/backup/file

Enabling diskspacemonitor

Make sure you have backed up any current crontab for root before enabling diskspacemonitor. That said, enabling this utility is very straight forward.

Step #2: Run the following:

[X:/] admin$ sudo diskspacemonitor on

If you receive the following output, don’t worry diskmonitor is actually enabled.

crontab: no crontab for root

You can check this by running:

[X:/] admin$ sudo diskspacemonitor status
Enabled: Monitor interval 10 minutes

Enabling diskspacemonitor is pretty much just adding an entry to root’s crontab (of course using the diskspacemonitor on command reads the config files and sets how often the diskspacemonitor check command is run). So the other way to check if it’s running is to display root’s crontab file. If diskspacemonitor is enabled you should get something like:

[X:/] admin$ sudo crontab -l
*/10 * * * * /usr/sbin/diskspacemonitor check

Configure Basic Settings

As mentioned in the introduction to diskspacemonitor, the main configuration file is /etc/diskspacemonitor/diskspacemonitor.conf. The comments in the configuration file make the variables pretty self-explanatory.

Step #3: Set the monitor_interval, alert_threshold, and recovery_threshold variables in diskspacemonitor.conf.

[X:/] admin$ sudo pico /etc/diskspacemonitor/diskspacemonitor.conf
# Config for diskspacemonitor

monitor_interval=10 # Check disks at this interval, in minutes

alert_threshold=75 # When a disk is this percentage full, execute
# the alert scripts in
# /etc/diskspacemonitor/action/

recovery_threshold=85 # When a disk is this percentage full, execute
# the recovery scripts in
# /etc/diskspacemonitor/action/


Note: Because this file is used to create the crontab entry, you need to re-enable diskspacemonitor every time you modify the monitor_interval variable. To do this, run the following in Terminal: sudo diskspacemonitor on. This will reload the variable and rewrite the crontab entry.

Configure Alert Script(s)

Now that you’ve setup when diskmonitor will check the system and at what thresholds actions will be taken, you should customize the alert script email settings.

Step #4: Set the to variable in /etc/diskspacemonitor/alert.conf to the email address you want the alert email to go to.

[X:/] admin$ sudo pico /etc/diskspacemonitor/alert.conf
# Config for alert

<code># Arguments passed to alert (and alert.local, if &lt;br&gt;
# it exists): &lt;br&gt;
# - Volume name &lt;br&gt;
# - Threshold &lt;br&gt;
# - Percentage full &lt;br&gt;
# - Log file &lt;br&gt;
# &lt;br&gt;
subject="DiskSpaceMonitor: Disk &amp;#36;1 has exceeded &amp;#36;2% threshold, is &amp;#36;3% full." &lt;br&gt;
to=admin &lt;br&gt;
body=`df -k -l -t ufs; df -k -l -t hfs` &lt;br&gt;

<code>If you're unfamiliar with shell scripting, the &amp;#36;1, &amp;#36;2, and &amp;#36;3 variables correspond with the 1st, 2nd, and 3rd variables/arguments that are passed to the alert script.

Step #4a: Delete the “-l” from the df commands in the body variable. You can test whether or not you need to do this by manually typing the df command on the server. If you get the following error, you will need to fix it.

[X:/] admin$ df -k -l -t hfs
df: -l and -t are mutually exclusive.

Check the Alert script

You will want to double-check that the alert script actually works. To do this simply change the alert_threshold variable to a percentage that you know will trigger the alert. If you don’t know what percentage that is, run the df command and look at the output.

Testing the mail command

If you are having email problems first double-check the diskspacemonitor log file then try testing out the unix mail application manually.

<code>The unix mail application should work (on OS X Server) by default.  To test it manually:
&lt;ul&gt;&lt;li&gt; open a shell on the server (SSH or locally).  
    &lt;li&gt;Type &lt;em&gt;mail your@emailaddress&lt;/em&gt; and press return.
    &lt;li&gt;Fill in the subject line and press return.
    &lt;li&gt;Type in the body of the text.
    &lt;li&gt;To exit and set the email type a period on its own line or ctrl-d on its own line.

Leave a reply

You must be logged in to post a comment.