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

Daniel Kral
2026-03-31T13:25:30Z

On Mon Mar 30, 2026 at 4:30 PM CEST, Daniel Kral wrote:
> diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
> index 04cd1bfe..b2488ddd 100644
> --- a/src/PVE/HA/Env/PVE2.pm
> +++ b/src/PVE/HA/Env/PVE2.pm
> @@ -588,6 +625,32 @@ sub get_static_node_stats {
> return $stats;
> }
>
> +sub get_dynamic_node_stats {
> + my ($self) = @_;
> +
> + my $rrd = PVE::Cluster::rrd_dump();
> +
> + my $stats = {};
> + for my $key (keys %$rrd) {
> + my ($nodename) = $key =~ m/^pve-node-9.0\/(\w+)$/;

Just noticed this while running on another setup, that `(\w+)` should be
replaced with an actual regex for valid nodenames, e.g.,
`([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)` from PVE::JSONSchema or
even just a `(\S+)` as we don't need to verify the nodename here.

e.g. 'pve-node1' would not work as the char '-' is not element of \w.

I'll wait for other test results before sending a v4 for this and the
other feedback.

> +
> + next if !$nodename;
> +
> + my $rrdentry = $rrd->{$key} // [];
> +
> + my $maxcpu = int($rrdentry->[RRD_NODE_INDEX_MAXCPU] || 0);
> +
> + $stats->{$nodename} = {
> + maxcpu => $maxcpu,
> + cpu => (($rrdentry->[RRD_NODE_INDEX_CPU] || 0.0) + 0.0) * $maxcpu,
> + maxmem => int($rrdentry->[RRD_NODE_INDEX_MAXMEM] || 0),
> + mem => int($rrdentry->[RRD_NODE_INDEX_MEM] || 0),
> + };
> + }
> +
> + return $stats;
> +}
> +
> sub get_node_version {
> my ($self, $node) = @_;
>