From d37fa4e6cc6ffb2834cefeb435e37fcf80b81156 Mon Sep 17 00:00:00 2001 From: zharkovstas Date: Tue, 19 Mar 2024 11:24:31 +0500 Subject: [PATCH] fix: do not log warnings about disabled net ifaces --- CHANGELOG.md | 4 ++++ .../Host/NetworkUtilizationCollector_Linux.cs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f634a..7b8e275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.21 (08-04-2024): + +Do not log warnings about disabled network interfaces on newer Linux kernels. + ## 0.3.20 (22-09-2023): Return back changes from 0.3.18 using RuntimeDetector to fix "Overlapped I/O operation is in progress" exception for framework 4.7.2/4.8. diff --git a/Vostok.Metrics.System/Host/NetworkUtilizationCollector_Linux.cs b/Vostok.Metrics.System/Host/NetworkUtilizationCollector_Linux.cs index d0a2ef5..9112752 100644 --- a/Vostok.Metrics.System/Host/NetworkUtilizationCollector_Linux.cs +++ b/Vostok.Metrics.System/Host/NetworkUtilizationCollector_Linux.cs @@ -145,7 +145,7 @@ NetworkUsage CreateNetworkUsage(string interfaceName, long receivedBytes, long s } // NOTE: See https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net for details. - // NOTE: This value equals -1 if interface is disabled, so we will filter this values out later. + // NOTE: This value equals -1 if interface is disabled on older kernels, so we will filter this values out later. foreach (var networkUsage in networkInterfacesUsage.Values) { if (TryReadSpeed(networkUsage.InterfaceName, out var result) && int.TryParse(result, out var speed)) @@ -235,6 +235,12 @@ private static bool TryReadSpeed(string interfaceName, out string result) result = File.ReadAllText(path); return true; } + // NOTE: Disabled interfaces give this error on newer kernels. + catch (IOException ioError) when (ioError.Message.StartsWith("Invalid argument")) + { + result = null; + return false; + } catch (Exception error) { // NOTE: We expect teaming interface to not be able to read speed directly.