From bc84e56ef7a86caf676cacd4b473016befd03dba Mon Sep 17 00:00:00 2001 From: Michael Howe Date: Thu, 27 Dec 2018 10:34:26 +0000 Subject: [PATCH] Add afs_volumes_partition_ plugin This plugin will graph the total usage of all volumes on a partition, and the allocated quota. (It really could do with a better name) --- plugins/afs_volumes_partition_ | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 plugins/afs_volumes_partition_ diff --git a/plugins/afs_volumes_partition_ b/plugins/afs_volumes_partition_ new file mode 100755 index 0000000..5ae1333 --- /dev/null +++ b/plugins/afs_volumes_partition_ @@ -0,0 +1,155 @@ +#!/usr/bin/perl + +=head1 NAME + +afs_volumes_partition_ - plugin to graph AFS partition quota allocation + +=head1 CONFIGURATION + +To monitor a specific partition, link to afs_volumes_partition_. +The following can be overriden using environment variables in the standard +munin way: + +server, timeout_cmd, timeout, vos + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=cut + +use strict; +use warnings; + +use v5.14.0; + +use Munin::Plugin; +use Net::Domain; + +my $VOS = $ENV{vos} // "/usr/bin/vos"; +my $TIMEOUT_CMD = $ENV{timeout_cmd} // "/usr/bin/timeout"; +my $TIMEOUT = $ENV{timeout} // 10; + +my $server = $ENV{server} // Net::Domain::hostfqdn(); + +sub partinfo { + my( $server, $partition ) = @_; + my @command = ( $VOS, 'partinfo', '-server', $server, '-noauth', '-partition', $partition ); + # if timeout cmd and interval are set, use them + # we use an external command because it's much, much easier + if( $TIMEOUT_CMD and $TIMEOUT ){ + unshift @command, $TIMEOUT_CMD, $TIMEOUT; + } + my $pinfo; + + unless( open( $pinfo, '-|', @command ) ){ + die "$Munin::Plugin::me: cannot contact server\n"; + } + my %results; + while( my $line = <$pinfo> ){ + # Free space on partition /vicepa: 1595716 K blocks out of total 4767360 + if( $line =~ m{/vicep[a-z]+:\s+(\d+) K.*total\s+(\d+)\s*$} ){ + $results{free} = $1; + $results{total} = $2; + $results{used} = $results{total} - $results{free}; + } + } + return %results; +} +sub serverinfo { + my( $server, $partition ) = @_; + my @command = ( $VOS, 'listvol', '-server', $server, '-long', '-noauth', '-partition', $partition ); + # if timeout cmd and interval are set, use them + # we use an external command because it's much, much easier + if( $TIMEOUT_CMD and $TIMEOUT ){ + unshift @command, $TIMEOUT_CMD, $TIMEOUT; + } + my $lvol; + + unless( open( $lvol, '-|', @command ) ){ + die "$Munin::Plugin::me: cannot contact server\n"; + } + + my( $volume, $size, %results ); + while( my $line = <$lvol> ){ + if ($line =~ /^(\S+)\s+\d+ RW\s+(\d+) K\s+On-line\s*$/) { + ($volume, $size) = ($1, $2); + my $orig_vol_name = $volume; + $volume =~ s{\.}{_}g; + $results{v}{$volume}{size} = $size; + $results{v}{$volume}{name} = $orig_vol_name; + $results{t}{size} += $size; + } elsif ($line =~ /^\s+MaxQuota\s+(\d+) K\s*$/ && defined $volume) { + $results{v}{$volume}{quota} = $1; + $results{v}{$volume}{percent} = sprintf "%.2f", ( $results{v}{$volume}{size} / $results{v}{$volume}{quota} * 100 ); + $results{t}{quota} += $1; + $volume = undef; + } elsif ($line =~ /^\s*$/) { # next volume + $volume = undef; + } + } + return %results; +} + +sub config { + my( $server, $partition ) = @_; + print <