Re: [PATCH ha-manager v2 20/40] env: pve2: implement dynamic node and service stats

Thomas Lamprecht
2026-03-25T21:42:51Z

Am 24.03.26 um 19:31 schrieb Daniel Kral:
> Fetch the dynamic node and service stats with rrd_dump(), which is
> periodically sampled and broadcasted by the PVE nodes' pvestatd service
> and propagated through the pmxcfs.

one small code issue inline that can be fixed up too on applying if nothing
else comes up.

>
> Signed-off-by: Daniel Kral <d.kral@proxmox.com>
> ---
> changes v1 -> v2:
> - use constants for the RRD entry indices
> - add note about the capping of the maxcpu property for guests
>
> src/PVE/HA/Env/PVE2.pm | 63 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
> index 04cd1bfe..4dfb304e 100644
> --- a/src/PVE/HA/Env/PVE2.pm
> +++ b/src/PVE/HA/Env/PVE2.pm

> @@ -569,6 +582,30 @@ sub get_static_service_stats {
> return $stats;
> }
>
> +sub get_dynamic_service_stats {
> + my ($self, $id) = @_;

this $id param is not directly used and no calling site passes any such
param, and it's also shadowed by the one inside the loop below.

> +
> + my $rrd = PVE::Cluster::rrd_dump();
> +
> + my $stats = get_cluster_service_stats();
> + for my $sid (keys %$stats) {
> + my $id = $stats->{$sid}->{id};
> + my $rrdentry = $rrd->{"pve-vm-9.0/$id"} // [];
> +
> + # NOTE the guests' broadcasted vmstatus() caps maxcpu at the node's maxcpu
> + my $maxcpu = ($rrdentry->[RRD_VM_INDEX_MAXCPU] || 0.0) + 0.0;
> +
> + $stats->{$sid}->{usage} = {
> + maxcpu => $maxcpu,
> + cpu => (($rrdentry->[RRD_VM_INDEX_CPU] || 0.0) + 0.0) * $maxcpu,
> + maxmem => int($rrdentry->[RRD_VM_INDEX_MAXMEM] || 0),
> + mem => int($rrdentry->[RRD_VM_INDEX_MEM] || 0),
> + };
> + }
> +
> + return $stats;
> +}
> +
> sub get_static_node_stats {
> my ($self) = @_;
>