mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 22:17:22 +01:00
add statistics
This commit is contained in:
parent
213fea5d41
commit
203fa1b194
4 changed files with 21 additions and 3 deletions
|
|
@ -17,6 +17,8 @@ public partial class MareHub
|
||||||
|
|
||||||
public string UserUID => Context.User?.Claims?.SingleOrDefault(c => string.Equals(c.Type, MareClaimTypes.Uid, StringComparison.Ordinal))?.Value ?? throw new Exception("No UID in Claims");
|
public string UserUID => Context.User?.Claims?.SingleOrDefault(c => string.Equals(c.Type, MareClaimTypes.Uid, StringComparison.Ordinal))?.Value ?? throw new Exception("No UID in Claims");
|
||||||
|
|
||||||
|
public string Continent => Context.User?.Claims?.SingleOrDefault(c => string.Equals(c.Type, MareClaimTypes.Continent, StringComparison.Ordinal))?.Value ?? "UNK";
|
||||||
|
|
||||||
private async Task DeleteUser(User user)
|
private async Task DeleteUser(User user)
|
||||||
{
|
{
|
||||||
var ownPairData = await DbContext.ClientPairs.Where(u => u.User.UID == user.UID).ToListAsync().ConfigureAwait(false);
|
var ownPairData = await DbContext.ClientPairs.Where(u => u.User.UID == user.UID).ToListAsync().ConfigureAwait(false);
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
|
||||||
[Authorize(Policy = "Authenticated")]
|
[Authorize(Policy = "Authenticated")]
|
||||||
public override async Task OnConnectedAsync()
|
public override async Task OnConnectedAsync()
|
||||||
{
|
{
|
||||||
_mareMetrics.IncGauge(MetricsAPI.GaugeConnections);
|
_mareMetrics.IncGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Continent);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -148,7 +148,7 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
|
||||||
[Authorize(Policy = "Authenticated")]
|
[Authorize(Policy = "Authenticated")]
|
||||||
public override async Task OnDisconnectedAsync(Exception exception)
|
public override async Task OnDisconnectedAsync(Exception exception)
|
||||||
{
|
{
|
||||||
_mareMetrics.DecGauge(MetricsAPI.GaugeConnections);
|
_mareMetrics.DecGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Continent);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,22 @@ public class MareMetrics
|
||||||
|
|
||||||
private readonly Dictionary<string, Gauge> _gauges = new(StringComparer.Ordinal);
|
private readonly Dictionary<string, Gauge> _gauges = new(StringComparer.Ordinal);
|
||||||
|
|
||||||
|
public void IncGaugeWithLabels(string gaugeName, double value = 1.0, params string[] labels)
|
||||||
|
{
|
||||||
|
if (_gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||||
|
{
|
||||||
|
gauge.WithLabels(labels).Inc(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DecGaugeWithLabels(string gaugeName, double value = 1.0, params string[] labels)
|
||||||
|
{
|
||||||
|
if (_gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||||
|
{
|
||||||
|
gauge.WithLabels(labels).Dec(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetGaugeTo(string gaugeName, double value)
|
public void SetGaugeTo(string gaugeName, double value)
|
||||||
{
|
{
|
||||||
if (_gauges.TryGetValue(gaugeName, out Gauge gauge))
|
if (_gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
public class MetricsAPI
|
public class MetricsAPI
|
||||||
{
|
{
|
||||||
public const string CounterInitializedConnections = "mare_initialized_connections";
|
public const string CounterInitializedConnections = "mare_initialized_connections";
|
||||||
public const string GaugeConnections = "mare_unauthorized_connections";
|
public const string GaugeConnections = "mare_connections";
|
||||||
public const string GaugeAuthorizedConnections = "mare_authorized_connections";
|
public const string GaugeAuthorizedConnections = "mare_authorized_connections";
|
||||||
public const string GaugeAvailableWorkerThreads = "mare_available_threadpool";
|
public const string GaugeAvailableWorkerThreads = "mare_available_threadpool";
|
||||||
public const string GaugeAvailableIOWorkerThreads = "mare_available_threadpool_io";
|
public const string GaugeAvailableIOWorkerThreads = "mare_available_threadpool_io";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue