From: Sandor W. Sklar (ssklar@STANFORD.EDU)
Date: Tue Mar 18 2003 - 19:23:49 EST
On Tuesday, March 18, 2003, at 12:31 PM, Miller, Dave ( I.S.) wrote:
> Anyone have or know of a simple script that monitors paging space
> utilization automatically...i.e. emails or pages etc. if it exceeds a
> given threshold?
you'll probably get hundreds ... here is what I use. run it out of
cron like ...
15,45 * * * * /usr/local/sbin/fsmon --threshold=95
-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#!/usr/bin/perl -w
# fsmon - monitor filesystems and yell when they are filling up
# $Id: fsmon,v 1.5 2002/08/06 15:43:26 ssklar Exp ssklar $
use strict;
use Getopt::Long;
use vars qw( $dfcmd $mailer $thishost $threshold $nooracle $mailto
$capacity $mountpoint );
if ($^O =~ /^aix/) {
$dfcmd = "/usr/bin/df -tk" ;
$mailer = "/usr/sbin/sendmail -oi -t ";
$thishost = `/usr/bin/hostname -s`
} elsif ($^O =~ /^sol/) {
$dfcmd = "/usr/bin/df -k";
$mailer = "/usr/lib/sendmail -oi -t ";
$thishost = `/usr/bin/hostname | /usr/bin/cut -f1 -d'.'`
} elsif ($^O =~ /^dar/) {
$dfcmd = "/bin/df -k";
$mailer = "/usr/sbin/sendmail -oi -t ";
$thishost = `/bin/hostname -s`
} else {
die "$0 : don't know df or mailer command for arch $^O\n"
};
chomp ($thishost);
# default values for threshold and mailto ...
$threshold = "90";
$mailto = getpwuid("$<");
# get user options ...
GetOptions ( 'threshold=i' => \$threshold,
'mailto=s' => \$mailto,
'nooracle' => \$nooracle,
'help|usage' => sub { exec "perldoc $0" } );
# and here we go ...
open (DF, "$dfcmd |") || die "$0 : failed to open read pipe to $dfcmd:
$!";
while (<DF>) {
next unless /^\/dev/; # skip NFS mounts, psudo-filesystems, etc.
($capacity, $mountpoint) = $_ =~ /\s+(\d+)%\s+(.*)/;
next if ( $nooracle && $mountpoint =~ /^\/u\d+$/ );
if ( $capacity > $threshold) {
notify_user ($mountpoint, $capacity)
};
};
sub notify_user {
$mountpoint = shift;
$capacity = shift;
open (MAIL, "| $mailer") || die "$0 : failed to open pipe to
$mailer:$!";
print MAIL "To: $mailto\n";
print MAIL "From: fsmon\@$thishost\n";
print MAIL "Reply-To: nobody\@$thishost\n";
print MAIL "Subject: $thishost:$mountpoint is at $capacity%\n\n";
close (MAIL)
};
=head1 FSMON
checks for full filesystems and sends email when a thrshold is
exceeded
=head1 Usage:
fsmon [--threshold=nn] [--mailto=address[,address2]] [--nooracle]
=head1 Options:
=item --threshold=nn
Send mail if the specified threshold (in percent) is exceeded. Default
is 90%.
=item --mailto=address[,address2]]
The address or addresses to which email will be sent when a filesystem
has exceeded the threshold. Default is the user who is running the
program.
=item --nooracle
Ignore filesystems that follow the Oracle OFA naming scheme, i.e.,
filesystems whose mountpoints begin with a lowercase "u" and have
nothing but digits following the "u".
=head1 Version:
=item $Id: fsmon,v 1.5 2002/08/06 15:43:26 ssklar Exp ssklar $
=cut
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:40 EDT