tracking filesystem usage with fsusage

I track filesystem usage on all my home machines using a small script which runs periodically. There are four pieces to this puzzle: fsusage, vixie-cron, syslog-ng and swatch. Of course you could swap out syslog-ng and swatch for your favorite logger and watcher, but the snippets I provide here are particular to those programs.

fsusage

The fsusage script itself is simple: It queries each local filesystem for usage information via df. If usage is 100% then it issues a RED alert to syslog. If usage is >=90% then it issues YELLOW alert to syslog. If usage is <90% then it issues a GREEN alert to syslog, but only if the previous level was non-GREEN.

Filename Date Size MD5
fsusage 09-Dec-2004 08:56 1.2K 4d352e60d0671b31f56f4f06d5d8d8b7

vixie-cron

Each machine runs fsusage once per minute using the following snippet in /etc/cron.d/fsusage.cron:

*/1 * * * *     root  /usr/local/bin/fsusage

syslog-ng

Each machine sends syslog data back to my primary workstation via the following lines in /etc/syslog-ng/syslog-ng.conf:

destination loghost { udp("10.0.0.6"); };
log { source(src); destination(loghost); };

My primary workstation accepts the syslog packets, and gives me ownership of the logfiles, with this snippet. These lines are in addition to the existing src and log lines that log for the local host.

options { 
    owner("agriffis");
};
source net { udp(); };
log { source(src); destination(messages); };

swatch

Finally, swatch runs in a screen session. It catches the notifications from fsusage and sends me mail or takes other appropriate actions. Here are the appropriate files to make that happen. (If you don't want to start in screen, then you can just run swatch in a terminal)

Filename Date Size MD5
swatch.init 09-Dec-2004 09:20 628  b31ce9286780a888fdae80a0c91d8f27
swatchrc 09-Dec-2004 09:22 484  ae41ab46a6fcb9292e500e0338d8f5ce

This page was generated Tue Jan 29 07:57:03 2008.