Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate active connection tracker #938

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/server/Metrics/GarnetServerMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal struct GarnetServerMetrics
/// </summary>
public long total_connections_received;
public long total_connections_disposed;
public long total_connections_active;

/// <summary>
/// Instantaneous metrics
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libs/server/Metrics/GarnetServerMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
vazois marked this conversation as resolved.
Show resolved Hide resolved

UpdateInstantaneousMetrics();
UpdateAllMetricsHistory();
Expand Down
4 changes: 3 additions & 1 deletion libs/server/Metrics/Info/GarnetInfoMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
1 change: 0 additions & 1 deletion libs/server/Metrics/Info/InfoCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using Garnet.common;

Expand Down
1 change: 0 additions & 1 deletion libs/server/Resp/ClientCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Linq;
using System.Text;
using Garnet.common;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Logging;

namespace Garnet.server
Expand Down
6 changes: 6 additions & 0 deletions libs/server/Servers/GarnetServerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public virtual IEnumerable<IMessageConsumer> ActiveConsumers()
return this.activeHandlers.Keys.Select(k => k.Session);
}

/// <summary>
/// Get total_connections_active
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long get_conn_active() => this.activeHandlers.Count;

/// <summary>
/// Get total_connections_received
/// </summary>
Expand Down
Loading