[pve-devel] [PATCH storage 2/2] Addition to #1542, get precent_used from RBDPlugin - add librados2-perl for rados commands - get RBD storage status through librados - calculate %USED if not available through librados (pre Kraken)
Fabian Grünbichler
f.gruenbichler at proxmox.com
Thu Nov 16 09:58:03 CET 2017
On Wed, Nov 15, 2017 at 03:47:28PM +0100, Alwin Antreich wrote:
> Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
> ---
> PVE/CLI/pvesm.pm | 1 +
> PVE/Storage.pm | 6 ++++--
> PVE/Storage/RBDPlugin.pm | 14 +++++++++++++-
> 3 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
> index 9455595..006f97f 100755
> --- a/PVE/CLI/pvesm.pm
> +++ b/PVE/CLI/pvesm.pm
> @@ -144,6 +144,7 @@ my $print_status = sub {
> my $active = $res->{active} ? 'active' : 'inactive';
> my ($per, $per_fmt) = (0, '% 7.2f%%');
> $per = ($res->{used}*100)/$res->{total} if $res->{total} > 0;
> + $per = $res->{percent_used} if $res->{percent_used};
but now the CLI and the GUI print different percentage values? if
anything, we'd need to adapt the API path to return percent_used (with a
fallback to the old calculation, either directly in the API path, or in
storage_info, or in the indiviual plugins), then we can patch the GUI
and pvesm to always simply use percent_used..
>
> if (!$res->{enabled}) {
> $per = 'N/A';
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index 73b21e1..ada9baf 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -1063,14 +1063,16 @@ sub storage_info {
> next;
> }
>
> - my ($total, $avail, $used, $active);
> - eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
> + my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
> + my ($total, $avail, $used, $active, $percent_used);
> + eval { ($total, $avail, $used, $active, $percent_used) = $plugin->status($storeid, $scfg, $cache); };
> warn $@ if $@;
> next if !$active;
> $info->{$storeid}->{total} = int($total);
> $info->{$storeid}->{avail} = int($avail);
> $info->{$storeid}->{used} = int($used);
> $info->{$storeid}->{active} = $active;
> + $info->{$storeid}->{percent_used} = $percent_used;
> }
>
> return $info;
> diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
> index 14386c4..74d19a8 100644
> --- a/PVE/Storage/RBDPlugin.pm
> +++ b/PVE/Storage/RBDPlugin.pm
> @@ -540,6 +540,8 @@ sub status {
> my $df_cmd = &$rados_mon_cmd('df');
> my $pg_cmd = &$rados_mon_cmd('pg dump');
>
> + my ($free, $used, $total, $percent_used) = 0;
> +
> foreach my $d (@{$df_cmd->{pools}}) {
> next if ($d->{name} ne $scfg->{pool});
> my $s_df = $d->{stats};
> @@ -547,8 +549,18 @@ sub status {
> my $used = $s_df->{bytes_used};
> my $total = $used + $free;
> my $active = 1;
> + my $calculation = 0;
> +
> + foreach my $e (@{$pg_cmd->{pool_stats}}) {
> + next if ($d->{id} ne $e->{poolid});
> + my $s_pg = $e->{stat_sum};
> + $calculation = $used * (($s_pg->{num_object_copies} - $s_pg->{num_objects_degraded}) / $s_pg->{num_object_copies});
> + $calculation /= ($calculation + $free);
> + }
> +
> + $percent_used = $s_df->{percent_used} ? $s_df->{percent_used} : ($calculation * 100);
so this means if 'df' already returned a percent_used, we don't even
need the whole calculation (and thus also no call to 'pg dump') ? ;)
do we even need this code at all then? when does 'df' not return a
percent_used value?
>
> - return ($total, $free, $used, $active);
> + return ($total, $free, $used, $active, $percent_used);
> }
> }
>
> --
> 2.11.0
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
More information about the pve-devel
mailing list