From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v2 2/5] api2tools: extract stats: handle existence of new pve-{type}-9.0 data
Date: Wed, 9 Jul 2025 18:36:53 +0200 [thread overview]
Message-ID: <20250709163703.2540012-14-a.lauterer@proxmox.com> (raw)
In-Reply-To: <20250709163703.2540012-1-a.lauterer@proxmox.com>
We add a new function to handle different key names, as it would
otherwise become quite unreadable.
It checks which key format exists for the type and resource:
* the old pve2-{type} / pve2.3-vm
* the new pve-{type}-{version}
and will return the one that was found. Since we will only have one key
per resource, we can return on the first hit.
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
Notes:
This patch also needs to be in PVE8 as otherwise those hosts won't be able
to extract stats from newer nodes -> question marks and missing info in
the GUI
changes since:
RFC:
* switch from pve9- to pve-{type}-9.0 schema
PVE/API2Tools.pm | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/PVE/API2Tools.pm b/PVE/API2Tools.pm
index 1e235c47..08548524 100644
--- a/PVE/API2Tools.pm
+++ b/PVE/API2Tools.pm
@@ -41,6 +41,24 @@ sub get_hwaddress {
return $hwaddress;
}
+# each rrd key for a resource will only exist once. The key format might be different though. Therefore return on first hit
+sub get_rrd_key {
+ my ($rrd, $type, $id) = @_;
+
+ # check for old formats: pve2-{type}/{id}. For VMs and CTs the version number is different than for nodes and storages
+ if ($type ne "vm" && exists $rrd->{"pve2-${type}/${id}"}) {
+ return "pve2-${type}/${id}";
+ } elsif ($type eq "vm" && exists $rrd->{"pve2.3-${type}/${id}"}) {
+ return "pve2.3-${type}/${id}";
+ }
+
+ # if no old key has been found, we expect on in the newer format: pve-{type}-{version}/{id}
+ # We accept all new versions, as the expectation is that they are only allowed to add new colums as non-breaking change
+ for my $k (keys %$rrd) {
+ return $k if $k =~ m/^pve-\Q${type}\E-\d\d?.\d\/\Q${id}\E$/;
+ }
+}
+
sub extract_node_stats {
my ($node, $members, $rrd, $exclude_stats) = @_;
@@ -51,8 +69,8 @@ sub extract_node_stats {
status => 'unknown',
};
- if (my $d = $rrd->{"pve2-node/$node"}) {
-
+ my $key = get_rrd_key($rrd, "node", $node);
+ if (my $d = $rrd->{$key}) {
if (
!$members || # no cluster
($members->{$node} && $members->{$node}->{online})
@@ -96,8 +114,9 @@ sub extract_vm_stats {
};
my $d;
+ my $key = get_rrd_key($rrd, "vm", $vmid);
- if ($d = $rrd->{"pve2.3-vm/$vmid"}) {
+ if (my $d = $rrd->{$key}) {
$entry->{uptime} = ($d->[0] || 0) + 0;
$entry->{name} = $d->[1];
@@ -135,7 +154,8 @@ sub extract_storage_stats {
content => $content,
};
- if (my $d = $rrd->{"pve2-storage/$node/$storeid"}) {
+ my $key = get_rrd_key($rrd, "storage", "${node}/${storeid}");
+ if (my $d = $rrd->{$key}) {
$entry->{maxdisk} = ($d->[1] || 0) + 0;
$entry->{disk} = ($d->[2] || 0) + 0;
$entry->{status} = 'available';
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-07-09 16:37 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 16:36 [pve-devel] [PATCH many v2 00/23] Expand and migrate RRD data (excluding GUI) Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster-pve8 v2 1/2] cfs status.c: drop old pve2-vm rrd schema support Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster-pve8 v2 2/2] status: handle new metrics update data Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager-pve8 v2 1/2] api2tools: drop old VM rrd schema Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager-pve8 v2 2/2] api2tools: extract stats: handle existence of new pve-{type}-9.0 data Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH pve9-rrd-migration-tool v2 1/1] introduce rrd migration tool for pve8 -> pve9 Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 1/4] cfs status.c: drop old pve2-vm rrd schema support Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 2/4] status: handle new metrics update data Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 3/4] status: introduce new pve-{type}- rrd and metric format Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 4/4] rrd: adapt to new RRD format with different aggregation windows Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH common v2 1/2] fix error in pressure parsing Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH common v2 2/2] add functions to retrieve pressures for vm/ct Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 1/5] api2tools: drop old VM rrd schema Aaron Lauterer
2025-07-09 16:36 ` Aaron Lauterer [this message]
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 3/5] pvestatd: collect and distribute new pve-{type}-9.0 metrics Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 4/5] api: nodes: rrd and rrddata add decade option and use new pve-node-9.0 rrd files Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 5/5] api2tools: extract_vm_status add new vm memhost column Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH storage v2 1/1] status: rrddata: use new pve-storage-9.0 rrd location if file is present Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH qemu-server v2 1/4] metrics: add pressure to metrics Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH qemu-server v2 2/4] vmstatus: add memhost for host view of vm mem consumption Aaron Lauterer
2025-07-09 16:37 ` [pve-devel] [PATCH qemu-server v2 3/4] vmstatus: switch mem stat to PSS of VM cgroup Aaron Lauterer
2025-07-09 16:37 ` [pve-devel] [PATCH qemu-server v2 4/4] rrddata: use new pve-vm-9.0 rrd location if file is present Aaron Lauterer
2025-07-09 16:37 ` [pve-devel] [PATCH container v2 1/2] metrics: add pressures to metrics Aaron Lauterer
2025-07-09 16:37 ` [pve-devel] [PATCH container v2 2/2] rrddata: use new pve-vm-9.0 rrd location if file is present Aaron Lauterer
2025-07-15 14:33 ` [pve-devel] SUPERSEEDED Re: [PATCH many v2 00/23] Expand and migrate RRD data (excluding GUI) Aaron Lauterer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250709163703.2540012-14-a.lauterer@proxmox.com \
--to=a.lauterer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.