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 868351FF16B for ; Tue, 29 Jul 2025 19:15:33 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4C3AD19365; Tue, 29 Jul 2025 19:16:56 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Tue, 29 Jul 2025 19:16:44 +0200 Message-ID: <20250729171649.708219-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250729171649.708219-1-s.hanreich@proxmox.com> References: <20250729171649.708219-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.194 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_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH pve-manager v2 1/2] pvestatd: pull metric: use ip link to detect physical interfaces 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" pve-common now allows arbitrary names for physical interfaces, without being restricted by PHYSICAL_NIC_RE. In order to detect physical interfaces, pvestatd now needs to query 'ip link' for the type of an interface instead of relying on the regular expression. On the receiving end, PullMetric cannot consult 'ip link' for determining which interface is physical or not. To work around that, introduce a new type key, that carries information about the type of an interface. When aggregating the metrics, PullMetric can now read this additional parameter, to infer the type of the interface (either physical or virtual). To avoid spawning a process in every update loop of pvestatd, cache the output once and then use it throughout the lifecycle of pvestatd. Physical interfaces rarely get added / removed without a reboot, so we can cache this indefinitely. Users can always restart the service to refresh the information about physical interfaces. Signed-off-by: Stefan Hanreich --- PVE/PullMetric.pm | 15 ++++++++++++--- PVE/Service/pvestatd.pm | 15 ++++++++++++++- services/pvestatd.service | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/PVE/PullMetric.pm b/PVE/PullMetric.pm index f55653505..24310c30e 100644 --- a/PVE/PullMetric.pm +++ b/PVE/PullMetric.pm @@ -91,9 +91,18 @@ my sub get_node_metrics { push @$metrics, gauge($id, $timestamp, "uptime", $data->{uptime}); my ($netin, $netout) = (0, 0); - for my $dev (grep { /^$PVE::Network::PHYSICAL_NIC_RE$/ } keys $data->{nics}->%*) { - $netin += $data->{nics}->{$dev}->{receive}; - $netout += $data->{nics}->{$dev}->{transmit}; + + for my $dev (keys $data->{nics}->%*) { + my $nic_data = $data->{nics}->{$dev}; + + if ($nic_data->{type}) { + next if $nic_data->{type} ne 'physical'; + } else { + next if $dev !~ /^$PVE::Network::PHYSICAL_NIC_RE$/; + } + + $netin += $nic_data->{receive}; + $netout += $nic_data->{transmit}; } push @$metrics, derive($id, $timestamp, "net_in", $netin); push @$metrics, derive($id, $timestamp, "net_out", $netout); diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm index e645eec3c..d662e3070 100755 --- a/PVE/Service/pvestatd.pm +++ b/PVE/Service/pvestatd.pm @@ -155,6 +155,8 @@ my sub broadcast_static_node_info { } } +my $cached_ip_links = undef; + sub update_node_status { my ($status_cfg, $pull_txn) = @_; @@ -171,9 +173,20 @@ sub update_node_status { my $sublevel = $subinfo->{level} || ''; my $netdev = PVE::ProcFSTools::read_proc_net_dev(); + $cached_ip_links = PVE::Network::ip_link_details() if !$cached_ip_links; + # traffic from/to physical interface cards my ($netin, $netout) = (0, 0); - for my $dev (grep { /^$PVE::Network::PHYSICAL_NIC_RE$/ } keys %$netdev) { + for my $dev (keys %$netdev) { + my $ip_link = $cached_ip_links->{$dev}; + + if (PVE::Network::ip_link_is_physical($ip_link)) { + $netdev->{$dev}->{type} = 'physical'; + } else { + $netdev->{$dev}->{type} = 'virtual'; + next; + } + $netin += $netdev->{$dev}->{receive}; $netout += $netdev->{$dev}->{transmit}; } diff --git a/services/pvestatd.service b/services/pvestatd.service index d7db50f6d..68a05305f 100644 --- a/services/pvestatd.service +++ b/services/pvestatd.service @@ -2,7 +2,7 @@ Description=PVE Status Daemon ConditionPathExists=/usr/bin/pvestatd Wants=pve-cluster.service -After=pve-cluster.service +After=pve-cluster.service pvenetcommit.service [Service] ExecStart=/usr/bin/pvestatd start -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel