Skip to content
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
14 changes: 12 additions & 2 deletions src/Microsoft.Azure.SignalR.Common/Endpoints/EndpointMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ namespace Microsoft.Azure.SignalR
public class EndpointMetrics
{
/// <summary>
/// <see cref="ServiceEndpoint" /> total concurrent client connection count on all hubs.
/// <see cref="ServiceEndpoint" /> total concurrent connected client connection count on all hubs.
/// </summary>
public int ClientConnectionCount { get; internal set; }

/// <summary>
/// <see cref="ServiceEndpoint" /> total concurrent connected server connection count on all hubs.
/// </summary>
public int ServerConnectionCount { get; internal set; }

/// <summary>
/// <see cref="ServiceEndpoint" /> connection quota for this instance, including client and server connections.
/// </summary>
public int ConnectionCapacity { get; internal set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ public virtual Task HandlePingAsync(PingMessage pingMessage)
{
Endpoint.EndpointMetrics.ClientConnectionCount = clientCount;
}

if (RuntimeServicePingMessage.TryGetServerCount(pingMessage, out var serverCount))
{
Endpoint.EndpointMetrics.ServerConnectionCount = serverCount;
}
if (RuntimeServicePingMessage.TryGetConnectionCapacity(pingMessage, out var connectionCapacity))
{
Endpoint.EndpointMetrics.ConnectionCapacity = connectionCapacity;
}
if (RuntimeServicePingMessage.TryGetStatus(pingMessage, out var status))
{
Log.ReceivedServiceStatusPing(Logger, status, Endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal static class RuntimeServicePingMessage
private const string ShutdownKey = "shutdown";
private const string ServersKey = "servers";
private const string ClientCountKey = "clientcount";
private const string ServerCountKey = "servercount";
private const string CapacityKey = "capacity";
private const string DiagnosticLogsMessagingTypeKey = "d-m";

private const string MessagingLogEnableValue = "1";
Expand Down Expand Up @@ -97,6 +99,28 @@ public static bool TryGetClientCount(this ServicePingMessage ping, out int clien
}
clientCount = count;
return true;
}

public static bool TryGetServerCount(this ServicePingMessage ping, out int serverCount)
Copy link
Contributor

@JialinXin JialinXin Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming to TryGetServerConnectionCount() to avoid confusing, since the another servers ping is trying to get server count...

{
if (!TryGetValue(ping, ServerCountKey, out var value) || !int.TryParse(value, out var count))
{
serverCount = 0;
return false;
}
serverCount = count;
return true;
}

public static bool TryGetConnectionCapacity(this ServicePingMessage ping, out int connectionCapacity)
{
if (!TryGetValue(ping, CapacityKey, out var value) || !int.TryParse(value, out var count))
{
connectionCapacity = 0;
return false;
}
connectionCapacity = count;
return true;
}

public static bool TryGetServersTag(this ServicePingMessage ping, out string serversTag, out long updatedTime)
Expand Down