From d1d5e11fd7c16d3a8c08724f41ccb333ec5c715f Mon Sep 17 00:00:00 2001 From: Vasileios Zois Date: Tue, 21 Jan 2025 10:25:56 -0800 Subject: [PATCH] added separate active connection tracker --- libs/server/Metrics/GarnetServerMetrics.cs | 2 ++ libs/server/Metrics/GarnetServerMonitor.cs | 1 + libs/server/Metrics/Info/GarnetInfoMetrics.cs | 4 +++- libs/server/Metrics/Info/InfoCommand.cs | 1 - libs/server/Resp/ClientCommands.cs | 1 - libs/server/Servers/GarnetServerBase.cs | 6 ++++++ 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/server/Metrics/GarnetServerMetrics.cs b/libs/server/Metrics/GarnetServerMetrics.cs index a17d9f8e3b..6ef2c45667 100644 --- a/libs/server/Metrics/GarnetServerMetrics.cs +++ b/libs/server/Metrics/GarnetServerMetrics.cs @@ -10,6 +10,7 @@ internal struct GarnetServerMetrics /// public long total_connections_received; public long total_connections_disposed; + public long total_connections_active; /// /// Instantaneous metrics @@ -38,6 +39,7 @@ public GarnetServerMetrics(bool trackStats, bool trackLatency, GarnetServerMonit { total_connections_received = 0; total_connections_disposed = 0; + total_connections_active = 0; instantaneous_cmd_per_sec = 0; instantaneous_net_input_tpt = 0; diff --git a/libs/server/Metrics/GarnetServerMonitor.cs b/libs/server/Metrics/GarnetServerMonitor.cs index 4e91e085f1..450c0b0a51 100644 --- a/libs/server/Metrics/GarnetServerMonitor.cs +++ b/libs/server/Metrics/GarnetServerMonitor.cs @@ -258,6 +258,7 @@ private async void MainMonitorTask(CancellationToken token) var garnetServer = ((GarnetServerBase)server); globalMetrics.total_connections_received = garnetServer.get_conn_recv(); globalMetrics.total_connections_disposed = garnetServer.get_conn_disp(); + globalMetrics.total_connections_active = garnetServer.get_conn_active(); UpdateInstantaneousMetrics(); UpdateAllMetricsHistory(); diff --git a/libs/server/Metrics/Info/GarnetInfoMetrics.cs b/libs/server/Metrics/Info/GarnetInfoMetrics.cs index 6f22598846..1203145682 100644 --- a/libs/server/Metrics/Info/GarnetInfoMetrics.cs +++ b/libs/server/Metrics/Info/GarnetInfoMetrics.cs @@ -169,9 +169,11 @@ private void PopulateStatsInfo(StoreWrapper storeWrapper) var globalMetrics = metricsDisabled ? default : storeWrapper.monitor.GlobalMetrics; var tt = metricsDisabled ? 0 : (double)(globalMetrics.globalSessionMetrics.get_total_found() + globalMetrics.globalSessionMetrics.get_total_notfound()); var garnet_hit_rate = metricsDisabled ? 0 : (tt > 0 ? (double)globalMetrics.globalSessionMetrics.get_total_found() / tt : 0) * 100; + statsInfo = [ - new("total_connections_active", metricsDisabled ? "0" : globalMetrics.total_connections_received.ToString()), + new("total_connections_active", metricsDisabled ? "0" : globalMetrics.total_connections_active.ToString()), + new("total_connections_received", metricsDisabled ? "0" : globalMetrics.total_connections_received.ToString()), new("total_connections_disposed", metricsDisabled ? "0" : globalMetrics.total_connections_disposed.ToString()), new("total_commands_processed", metricsDisabled ? "0" : globalMetrics.globalSessionMetrics.get_total_commands_processed().ToString()), new("instantaneous_ops_per_sec", metricsDisabled ? "0" : globalMetrics.instantaneous_cmd_per_sec.ToString()), diff --git a/libs/server/Metrics/Info/InfoCommand.cs b/libs/server/Metrics/Info/InfoCommand.cs index a90f3874ea..4233a02175 100644 --- a/libs/server/Metrics/Info/InfoCommand.cs +++ b/libs/server/Metrics/Info/InfoCommand.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using System; using System.Collections.Generic; using Garnet.common; diff --git a/libs/server/Resp/ClientCommands.cs b/libs/server/Resp/ClientCommands.cs index ec5c46d6e2..dd4bc2128a 100644 --- a/libs/server/Resp/ClientCommands.cs +++ b/libs/server/Resp/ClientCommands.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Text; using Garnet.common; -using Microsoft.Extensions.Azure; using Microsoft.Extensions.Logging; namespace Garnet.server diff --git a/libs/server/Servers/GarnetServerBase.cs b/libs/server/Servers/GarnetServerBase.cs index 5911207b83..605a199493 100644 --- a/libs/server/Servers/GarnetServerBase.cs +++ b/libs/server/Servers/GarnetServerBase.cs @@ -85,6 +85,12 @@ public virtual IEnumerable ActiveConsumers() return this.activeHandlers.Keys.Select(k => k.Session); } + /// + /// Get total_connections_active + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public long get_conn_active() => this.activeHandlers.Count; + /// /// Get total_connections_received ///