Skip to content

Commit

Permalink
fix: do not log warnings about disabled net ifaces
Browse files Browse the repository at this point in the history
  • Loading branch information
zharkovstas committed Mar 19, 2024
1 parent 641dce2 commit 03866c8
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 03866c8

Please sign in to comment.