root/lib/Resmon/Module/ZPOOLFREE.pm

Revision cfdffd96e55a10cc596590c9dd92f172422a39f0, 1.7 kB (checked in by Mark Harrison <mark@omniti.com>, 6 years ago)

Fix to ZPOOLFREE check to use the more accurate zfs list instead of zpool list

git-svn-id: https://labs.omniti.com/resmon/trunk@154 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100755
Line 
1 package Resmon::Module::ZPOOLFREE;
2
3 use Resmon::Module;
4 use Resmon::ExtComm qw/cache_command/;
5
6 use vars qw/@ISA/;
7 @ISA = qw/Resmon::Module/;
8
9 # Version of the free space module that uses zfs list instead of df
10 #
11 # Note: this check used to use zpool list, but this doesn't report accurate
12 # values due to a space reservation. See
13 # http://cuddletech.com/blog/pivot/entry.php?id=1013 for an explanation of
14 # this.
15 #
16 # Sample config:
17 #
18 # ZPOOLFREE {
19 #   intmirror           : limit => 90%
20 #   storage1            : limit => 90%
21 # }
22
23 sub handler {
24   my $self = shift;
25   my $object = $self->{object};
26   my %units = (
27       'B' => 1,
28       'K' => 1024,
29       'M' => 1048576,
30       'G' => 1073741824,
31       'T' => 1099511627776,
32       'P' => 1125899906842624,
33       'E' => 1152921504606846976,
34       'Z' => 1180591620717411303424
35   );
36   if ($object =~ /\//) {
37       return "BAD", "Dataset name $object is not the root of a zpool"
38   }
39   # -H prints script friendly output
40   my $output = cache_command("zfs list -H $object", 120);
41   my ($used, $uunit, $free, $funit) =
42     $output =~ /$object\t([0-9.]+)([BKMGTPEZ]?)\t([0-9.]+)([BKMGTPEZ]?)/;
43   if (!$used) {
44       return "BAD", "no data";
45   }
46   my $hused = "${used}${uunit}";
47   my $hfree = "${free}${funit}";
48   # Convert from human readable units
49   $used = $used * $units{$uunit} if $uunit;
50   $free = $free * $units{$funit} if $funit;
51   my $total = $used + $free;
52   my $percent = ($used / $total) * 100;
53   my $status;
54   if($percent > $self->{'limit'}) {
55     $status = "BAD";
56   } elsif(exists $self->{'warnat'} && $1 > $self->{'warnat'}) {
57     $status = "WARNING";
58   } else {
59     $status = "OK";
60   }
61   return $status, sprintf("%.0f%% full, %s used, %s free",
62     $percent, $hused, $hfree);
63 }
64
65 1;
Note: See TracBrowser for help on using the browser.