From 0a8cd1906cb5aa09d2906e6de7ee29c18d770fa0 Mon Sep 17 00:00:00 2001 From: tebaikin Date: Sun, 26 Nov 2023 14:38:28 +0500 Subject: [PATCH] fix --- .../Host/TcpStateCollector.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Vostok.Metrics.System/Host/TcpStateCollector.cs b/Vostok.Metrics.System/Host/TcpStateCollector.cs index 9b04b96..be13b9c 100644 --- a/Vostok.Metrics.System/Host/TcpStateCollector.cs +++ b/Vostok.Metrics.System/Host/TcpStateCollector.cs @@ -28,14 +28,26 @@ public void Collect(HostMetrics metrics) var states = new Dictionary(); #if NET6_0_OR_GREATER - - IterateOverTcpConnections(info => + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - if (!states.ContainsKey(info.State)) - states[info.State] = 0; - states[info.State]++; - }); - + IterateOverTcpConnections(info => + { + if (!states.ContainsKey(info.State)) + states[info.State] = 0; + states[info.State]++; + }); + } + else + { + foreach (var tcpConnection in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections()) + { + if (!states.ContainsKey(tcpConnection.State)) + states[tcpConnection.State] = 0; + states[tcpConnection.State]++; + } + } + #else foreach (var tcpConnection in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections())