Fetch dynamic node and service stats from the rrd_dump() propagated through the pmxcfs periodically.
Signed-off-by: Daniel Kral <[email protected]> --- src/PVE/HA/Env/PVE2.pm | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm index d5c20460..bb0d8c74 100644 --- a/src/PVE/HA/Env/PVE2.pm +++ b/src/PVE/HA/Env/PVE2.pm @@ -559,6 +559,30 @@ sub get_static_service_stats { return $stats; } +sub get_dynamic_service_stats { + my ($self, $id) = @_; + + 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"} // []; + + # FIXME $rrdentry->[5] is the problematic $d->{cpus} from vmstatus + my $maxcpu = ($rrdentry->[5] || 0.0) + 0.0; + + $stats->{$sid}->{usage} = { + maxcpu => $maxcpu, + cpu => (($rrdentry->[6] || 0.0) + 0.0) * $maxcpu, + maxmem => int($rrdentry->[7] || 0), + mem => int($rrdentry->[8] || 0), + }; + } + + return $stats; +} + sub get_static_node_stats { my ($self) = @_; @@ -578,6 +602,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+)$/; + + next if !$nodename; + + my $rrdentry = $rrd->{$key} // []; + + my $maxcpu = int($rrdentry->[4] || 0); + + $stats->{$nodename} = { + maxcpu => $maxcpu, + cpu => (($rrdentry->[5] || 0.0) + 0.0) * $maxcpu, + maxmem => int($rrdentry->[7] || 0), + mem => int($rrdentry->[8] || 0), + }; + } + + return $stats; +} + sub get_node_version { my ($self, $node) = @_; -- 2.47.3
