Changeset cfdffd96e55a10cc596590c9dd92f172422a39f0

Show
Ignore:
Timestamp:
01/21/09 18:12:38 (5 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1232561558 +0000
git-parent:

[d75bc41ea17e2fac447a58bb98a98fcf5a465160]

git-author:
Mark Harrison <mark@omniti.com> 1232561558 +0000
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/Resmon/Module/ZPOOLFREE.pm

    rae22e3b rcfdffd9  
    77@ISA = qw/Resmon::Module/; 
    88 
    9 # Version of the free space module that uses zpool list instead of df 
     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
    1016# Sample config: 
    1117# 
     
    1824  my $self = shift; 
    1925  my $object = $self->{object}; 
    20   my $output = cache_command("zpool list", 120); 
    21   my ($line) = grep(/$object\s*/, split(/\n/, $output)); 
    22   if($line =~ /(\d+)%/) { 
    23     if($1 > $self->{'limit'}) { 
    24       return "BAD", "$1% full"; 
    25     } 
    26     if(exists $self->{'warnat'} && $1 > $self->{'warnat'}) { 
    27       return "WARNING", "$1% full"; 
    28     } 
    29     return "OK", "$1% full"; 
     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" 
    3038  } 
    31   return "BAD", "0 no data"; 
     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); 
    3263} 
    3364