Skip to content
Snippets Groups Projects
Commit c3d87d4c authored by Mark Harrison's avatar Mark Harrison
Browse files

Fix for when snapshots are present

The method used has also changed to use zpool list then zfs list on individual
filesystems. This is because zfs list can be very slow if there are a lot
of filesystems present.

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@338 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent 70fa1f16
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,10 @@ where zpool list does not report the true usable free space (e.g. raidz
pools). See http://www.cuddletech.com/blog/pivot/entry.php?id=1013 for another
case where zpool list does not report the correct values for monitoring.
Zpool list is still used to get the list of pools on the system, and then zfs
list is run individually for each pool. This is done to improve performance in
the case where there are many filesystems.
=head1 CONFIGURATION
=over
......@@ -47,6 +51,10 @@ The check name is descriptive only in this check. It is not used for anything.
Specify an alternative location for the zfs command. Default: /sbin/zfs.
=item zpool_path
Specify an alternative location for the zpool command. Default: /sbin/zpool.
=back
=head1 METRICS
......@@ -90,13 +98,19 @@ sub handler {
my $self = shift;
my $config = $self->{config}; # All configuration is in here
my $zfs_command = $config->{zfs_command} || "/sbin/zfs";
my $zpool_command = $config->{zpool_command} || "/sbin/zpool";
my $status = {};
my $output = run_command("$zfs_command list -H -o name,used,avail");
foreach my $line (split /\n/, $output) {
my ($name, $used, $uunit, $free, $funit) = $line =~
my $output = run_command("$zpool_command list -H -o name");
foreach my $pool (split /\n/, $output) {
# Sanity check in case zpool outputs something strange
die "Invalid pool name: $pool" if $pool !~ /[a-zA-Z0-9_.-]+/;
my $zfs_output = run_command(
"$zfs_command list -H -o name,used,avail $pool");
my ($name, $used, $uunit, $free, $funit) = $zfs_output =~
/(\S+)\s+([0-9.]+)([BKMGTPEZ]?)\s+([0-9.]+)([BKMGTPEZ]?)/;
# Make sure we were able to match the regex
die "Unable to parse zfs command output: $line\n" unless defined($name);
die "Unable to parse zfs command output: $zfs_output\n"
unless defined($name);
next if ($name =~ /\//); # We're only interested in the root of a pool
# Convert human readable units to bytes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment