From: Russ Allbery Date: Thu, 23 Dec 2010 22:04:55 +0000 (-0800) Subject: Add optional performance data to check_afs_space X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=9bef986514f8027fd66c842346f5608e23bc7a4e;p=packages%2Fa%2Fafs-monitor.git Add optional performance data to check_afs_space Add a -d flag to check_afs_space that prints out Nagios performance data for the percent usage of each partition checked. Based on a patch by Breandan Dezendorf. --- diff --git a/NEWS b/NEWS index dc41aef..c1139b1 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ afs-monitor 2.2 (unreleased) + Add a -d flag to check_afs_space that prints out Nagios performance + data for the percent usage of each partition checked. Based on a + patch by Breandan Dezendorf. + The vos binary is installed in sbin by the Red Hat packages and the default upstream installation rules, so check in sbin as well as bin. Patch from Daniel Scott. Also fall back, for all AFS binaries, to diff --git a/check_afs_space b/check_afs_space index 7dd2da9..07735e4 100755 --- a/check_afs_space +++ b/check_afs_space @@ -67,9 +67,10 @@ sub syntax { } # Parse command line options. -my ($help, $host, $partition, $version); +my ($help, $host, $partition, $printdata, $version); Getopt::Long::config ('bundling', 'no_ignore_case'); GetOptions ('c|critical=i' => \$CRITICAL, + 'd|perfdata' => \$printdata, 'H|hostname=s' => \$host, 'h|help' => \$help, 'p|partition=s' => \$partition, @@ -81,8 +82,7 @@ if ($help) { print "Feeding myself to perldoc, please wait....\n"; exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n"; } elsif ($version) { - my $version = $VERSION; - print "check_afs_space $version\n"; + print "check_afs_space $VERSION\n"; exit 0; } syntax ("extra arguments on command line") if @ARGV; @@ -104,8 +104,9 @@ alarm ($TIMEOUT); # Get the partinfo information and calculate the percentage free for each # partition. Accumulate critical messages in @critical and warnings in -# @warnings. Accumulate all percentages in @all. -my (@critical, @warnings, @all); +# @warnings. Accumulate all percentages in @all. Accumulate performance data +# in @perfdata. +my (@critical, @warnings, @all, @perfdata); my $command = "$VOS partinfo -server '$host'"; $command .= " -partition $partition" if defined ($partition); my @data = `$command 2> /dev/null`; @@ -124,6 +125,9 @@ for (@data) { $free = format_bytes ($free, mode => 'iec'); $used = format_bytes ($used, mode => 'iec'); } + my $ppart = $part . '_percent'; + $ppart =~ tr%:/%%d; + push (@perfdata, "$ppart=$percent\%;$WARNINGS;$CRITICAL;0;100"); my $summary; if ($partition) { $summary = "$part$percent% used" @@ -148,14 +152,18 @@ unless (@all) { } # Exit with the appropriate error messages. +my $perfdata = ''; +if ($printdata) { + $perfdata = ' | ' . join (' ', @perfdata); +} if (@critical) { - print "AFS CRITICAL - @critical\n"; + print "AFS CRITICAL - @critical$perfdata\n"; exit 2; } elsif (@warnings) { - print "AFS WARNING - @warnings\n"; + print "AFS WARNING - @warnings$perfdata\n"; exit 1; } else { - print "AFS OK - @all\n"; + print "AFS OK - @all$perfdata\n"; exit 0; } @@ -169,7 +177,7 @@ check_afs_space - Monitor AFS disk space usage under Nagios =head1 SYNOPSIS -B [B<-hV>] [B<-c> I] [B<-w> I] +B [B<-dhV>] [B<-c> I] [B<-w> I] [B<-p> I] [B<-t> I] B<-H> I =head1 DESCRIPTION @@ -203,6 +211,14 @@ about the total, used, and free space is given in the one line of output. Change the critical percentage threshold to I, which should be an integer percentage. The default is 90. +=item B<-d>, B<--perfdata> + +Include performance data in the plugin output. This adds an additional +section of the output following a vertical bar (C<|>) following the Nagios +plugin standard for performance data. There will be one variable for each +partition checked, named C_percent>, where I is the +partition without the leading slash. The value will be the usage percentage. + =item B<-H> I, B<--hostname>=I The AFS file server whose free space B should check. This