diff --git a/duwatch/GNUmakefile b/duwatch/GNUmakefile new file mode 100644 index 0000000..c1edc9f --- /dev/null +++ b/duwatch/GNUmakefile @@ -0,0 +1,9 @@ +install: $(ROOT)/usr/local/bin/duwatch +install_all: + make install ROOT=/nfs/wsrdb + make install ROOT=/nfs/wifosv + make install ROOT=/nfs/ihssv + make install ROOT=/nfs/wsrcom + +$(ROOT)/usr/local/bin/%: % + install $< $@ diff --git a/duwatch/duwatch b/duwatch/duwatch new file mode 100755 index 0000000..d621cac --- /dev/null +++ b/duwatch/duwatch @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +$avgfile = "/usr/local/lib/duwatch.avg"; +$root = "/"; +$thresh = 20000; +$period = 30; + +open AVG, $avgfile || die; +while () { + ($size, $name) = split; + $avgdu{$name} = $size; + $all{$name} = 1; +} +close AVG; + +open NEW, "/bin/du -t hfs $root |" || die; +while () { + ($size, $name) = split; + $size /= 2; # du reports 512 byte blocks :-( + if ($size < $thresh) {next}; + $newdu{$name} = $size; + $all{$name} = 1; +} +close NEW; + +for $i (keys %all) { + if ($newdu{"$i"} > 2 * ($avgdu{"$i"})) { + printf "%s: %d -> %d\n", $i, $avgdu{$i}, $newdu{$i}; + } + $avgdu{$i} = ($avgdu{$i} * ($period - 1) + $newdu{$i}) / $period; +} + +open AVG, ">" . $avgfile || die; +for $i (keys %avgdu) { + printf AVG "%d %s\n", $avgdu{$i}, $i; +} +close AVG;