[Resmon-devel] [resmon commit] r338 - branches/resmon2/lib/Core

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Thu Apr 29 15:39:54 EDT 2010

Author: mark
Date: 2010-04-29 15:39:54 -0400 (Thu, 29 Apr 2010)
New Revision: 338

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.

Modified: branches/resmon2/lib/Core/ZpoolFree.pm
--- branches/resmon2/lib/Core/ZpoolFree.pm	2010-04-28 15:31:34 UTC (rev 337)
+++ branches/resmon2/lib/Core/ZpoolFree.pm	2010-04-29 19:39:54 UTC (rev 338)
@@ -35,6 +35,10 @@
 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.
@@ -47,6 +51,10 @@
 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.
 =head1 METRICS
@@ -90,13 +98,19 @@
     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 =~
         # 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

More information about the Resmon-devel mailing list