[pve-devel] [PATCH storage 1/2] Fix: 1542 - show storage utilization per pool, not per global

Alwin Antreich a.antreich at proxmox.com
Wed Nov 15 15:47:27 CET 2017


Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 PVE/Storage/RBDPlugin.pm | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index decfbf5..14386c4 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -7,6 +7,7 @@ use Net::IP;
 use PVE::Tools qw(run_command trim);
 use PVE::Storage::Plugin;
 use PVE::JSONSchema qw(get_standard_option);
+use PVE::RADOS;
 
 use base qw(PVE::Storage::Plugin);
 
@@ -90,6 +91,15 @@ my $rados_cmd = sub {
     return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options);
 };
 
+my $rados_mon_cmd = sub {
+    my ($cmd) = @_;
+
+    my $rados = PVE::RADOS->new();
+    my $res = $rados->mon_command({ prefix => $cmd, format => 'json' });
+
+    return $res;
+};
+
 # needed for volumes created using ceph jewel (or higher)
 my $krdb_feature_disable = sub {
     my ($scfg, $storeid, $name) = @_;
@@ -527,32 +537,20 @@ sub list_images {
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
-    my $cmd = &$rados_cmd($scfg, $storeid, 'df');
-
-    my $stats = {};
-
-    my $parser = sub {
-	my $line = shift;
-	if ($line =~ m/^\s*total(?:\s|_)(\S+)\s+(\d+)(k|M|G|T)?/) {
-	    $stats->{$1} = $2;
-	    # luminous has units here..
-	    if ($3) {
-		$stats->{$1} *= $rbd_unittobytes->{$3}/1024;
-	    }
-	}
-    };
-
-    eval {
-	run_rbd_command($cmd, errmsg => "rados error", errfunc => sub {}, outfunc => $parser);
-    };
+    my $df_cmd = &$rados_mon_cmd('df');
+    my $pg_cmd = &$rados_mon_cmd('pg dump');
 
-    my $total = $stats->{space} ? $stats->{space}*1024 : 0;
-    my $free = $stats->{avail} ? $stats->{avail}*1024 : 0;
-    my $used = $stats->{used} ? $stats->{used}*1024: 0;
+    foreach my $d (@{$df_cmd->{pools}}) {
+	next if ($d->{name} ne $scfg->{pool});
+	my $s_df = $d->{stats};
+	my $free = $s_df->{max_avail};
+	my $used = $s_df->{bytes_used};
+	my $total = $used + $free;
 	my $active = 1;
 
 	return ($total, $free, $used, $active);
     }
+}
 
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;
-- 
2.11.0





More information about the pve-devel mailing list