all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-manager 1/2] pvestatd: pull metric: use ip link to detect physical interfaces
Date: Thu, 24 Jul 2025 16:49:58 +0200	[thread overview]
Message-ID: <20250724144959.374061-3-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250724144959.374061-1-s.hanreich@proxmox.com>

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. For now
we only set the type for physical interfaces, otherwise to unknown.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 PVE/PullMetric.pm       | 15 ++++++++++++---
 PVE/Service/pvestatd.pm | 13 ++++++++++++-
 2 files changed, 24 insertions(+), 4 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..c91adeca8 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -171,9 +171,20 @@ sub update_node_status {
     my $sublevel = $subinfo->{level} || '';
 
     my $netdev = PVE::ProcFSTools::read_proc_net_dev();
+    my $ip_links = PVE::Network::ip_link_details();
+
     # 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 = $ip_links->{$dev};
+
+        if (PVE::Network::ip_link_is_physical($ip_link)) {
+            $netdev->{$dev}->{type} = 'physical';
+        } else {
+            $netdev->{$dev}->{type} = 'unknown';
+            next;
+        }
+
         $netin += $netdev->{$dev}->{receive};
         $netout += $netdev->{$dev}->{transmit};
     }
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-07-24 14:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-24 14:49 [pve-devel] [RFC common/manager 0/3] arbitrary prefixes for pinning network interfaces Stefan Hanreich
2025-07-24 14:49 ` [pve-devel] [PATCH pve-common 1/1] inotify/interfaces: use ip link for detecting physical interfaces Stefan Hanreich
2025-07-24 14:49 ` Stefan Hanreich [this message]
2025-07-24 14:49 ` [pve-devel] [PATCH pve-manager 2/2] network-interface-pinning: allow arbitrary names Stefan Hanreich
2025-07-29 17:17 ` [pve-devel] superseded: [RFC common/manager 0/3] arbitrary prefixes for pinning network interfaces Stefan Hanreich

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=20250724144959.374061-3-s.hanreich@proxmox.com \
    --to=s.hanreich@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal