Refactor code structure for improved readability and maintainability; optimize performance in key functions.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Linq;
|
||||
using StellaOps.Router.Common.Abstractions;
|
||||
|
||||
namespace StellaOps.Gateway.WebService.Services;
|
||||
|
||||
public sealed class GatewayMetrics
|
||||
{
|
||||
public const string MeterName = "StellaOps.Gateway.WebService";
|
||||
|
||||
private static readonly Meter Meter = new(MeterName, "1.0.0");
|
||||
private readonly IGlobalRoutingState _routingState;
|
||||
|
||||
public GatewayMetrics(IGlobalRoutingState routingState)
|
||||
{
|
||||
_routingState = routingState;
|
||||
|
||||
Meter.CreateObservableGauge(
|
||||
"gateway_active_connections",
|
||||
() => GetActiveConnections(),
|
||||
description: "Number of active microservice connections.");
|
||||
|
||||
Meter.CreateObservableGauge(
|
||||
"gateway_registered_endpoints",
|
||||
() => GetRegisteredEndpoints(),
|
||||
description: "Number of registered endpoints across all connections.");
|
||||
}
|
||||
|
||||
public long GetActiveConnections()
|
||||
{
|
||||
return _routingState.GetAllConnections().Count;
|
||||
}
|
||||
|
||||
public long GetRegisteredEndpoints()
|
||||
{
|
||||
return _routingState.GetAllConnections().Sum(c => c.Endpoints.Count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user