]> git.proxmox.com Git - pve-storage.git/commitdiff
pvesm status: improve output and its format
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 27 Jul 2017 10:16:46 +0000 (12:16 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 27 Jul 2017 11:09:28 +0000 (13:09 +0200)
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@proxmox.com>
PVE/CLI/pvesm.pm

index 9adc8bacf58dca55ec3648b76344d1c0ba7b4fcf..ec6d865bfe03837e0f55562765c446b3c5dc28f7 100755 (executable)
@@ -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;
     }
 };