From: Thomas Lamprecht Date: Thu, 27 Jul 2017 10:16:46 +0000 (+0200) Subject: pvesm status: improve output and its format X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=d40e27deb264bdbec224a973a4778b988c18ed99;p=pve-storage.git pvesm status: improve output and its format 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 --- 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; } };