[pve-devel] [PATCH storage v4 2/2] pvesm status: improve output and its format

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jul 27 12:16:46 CEST 2017


Add column names at top of output, this allows easier understanding
of what each column means.

Use leading spaces on the percentage column so that this is lined up.

Switch out the 1/0 from the active column with the actual status
(active, inactive, disabled).

Show N/A if storage is disabled.

Use $res->{total} instead of calculating a sum of used and available.

Remove wrong rounding - if we want to display 2 digits from the
fractional part we would need to add 0.005 not 0.5, this made the
result quite wrong depending on the storage size.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

changes v3 -> v4:
 * show N/A instead of 100% if a storage is disabled
 * fix header capitalization (missed first row)
 * omint wrong rounding
 * use $res->{total} for percentage calculation


 PVE/CLI/pvesm.pm | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
index 9adc8ba..ec6d865 100755
--- a/PVE/CLI/pvesm.pm
+++ b/PVE/CLI/pvesm.pm
@@ -135,15 +135,25 @@ my $print_status = sub {
     }
     $maxlen+=1;
 
+    printf "%-${maxlen}s %10s %10s %15s %15s %15s %8s\n", 'Name', 'Type',
+	'Status', 'Total', 'Used', 'Available', '%';
+
     foreach my $res (sort { $a->{storage} cmp $b->{storage} } @$res) {
 	my $storeid = $res->{storage};
 
-	my $sum = $res->{used} + $res->{avail};
-	my $per = $sum ? (0.5 + ($res->{used}*100)/$sum) : 100;
+	my $active = $res->{active} ? 'active' : 'inactive';
+	my ($per, $per_fmt) = (0, '% 7.2f%%');
+	$per = ($res->{used}*100)/$res->{total} if $res->{total} > 0;
+
+	if (!$res->{enabled}) {
+	    $per = 'N/A ';
+	    $per_fmt = '% 8s';
+	    $active = 'disabled';
+	}
 
-	printf "%-${maxlen}s %5s %1d %15d %15d %15d %.2f%%\n", $storeid,
-	$res->{type}, $res->{active},
-	$res->{total}/1024, $res->{used}/1024, $res->{avail}/1024, $per;
+	printf "%-${maxlen}s %10s %10s %15d %15d %15d $per_fmt\n", $storeid,
+	    $res->{type}, $active, $res->{total}/1024, $res->{used}/1024,
+	    $res->{avail}/1024, $per;
     }
 };
 
-- 
2.11.0





More information about the pve-devel mailing list