From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 876E61FF16B for ; Tue, 15 Jul 2025 16:32:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 953E33FCEA; Tue, 15 Jul 2025 16:32:28 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Tue, 15 Jul 2025 16:31:59 +0200 Message-Id: <20250715143218.1548306-16-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715143218.1548306-1-a.lauterer@proxmox.com> References: <20250715143218.1548306-1-a.lauterer@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.019 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_MAILER 2 Automated Mailer Tag Left in Email RCVD_IN_MSPIKE_H2 0.001 Average reputation (+2) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH manager v3 02/14] api2tools: extract stats: handle existence of new pve-{type}-9.0 data X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 --- Notes: 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