lock metrics calls

This commit is contained in:
Stanley Dimant
2022-07-17 01:13:29 +02:00
parent 69930f8da6
commit 130350b71b
10 changed files with 135 additions and 58 deletions

View File

@@ -8,6 +8,7 @@ using System.Threading;
using System.Threading.Tasks;
using MareSynchronos.API;
using MareSynchronosServer.Authentication;
using MareSynchronosServer.Metrics;
using MareSynchronosServer.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;

View File

@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using MareSynchronos.API;
using MareSynchronosServer.Authentication;
using MareSynchronosServer.Metrics;
using MareSynchronosServer.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;

View File

@@ -5,6 +5,7 @@ using System.Security.Cryptography;
using System.Threading.Tasks;
using MareSynchronos.API;
using MareSynchronosServer.Data;
using MareSynchronosServer.Metrics;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -55,10 +56,6 @@ namespace MareSynchronosServer.Hubs
IsAdmin = user.IsAdmin
};
}
else
{
MareMetrics.UnauthorizedConnections.Inc();
}
return new ConnectionDto()
{
@@ -72,6 +69,12 @@ namespace MareSynchronosServer.Hubs
return _systemInfoService.SystemInfoDto;
}
public override Task OnConnectedAsync()
{
MareMetrics.Connections.Inc();
return base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
var user = await _dbContext.Users.AsNoTracking().SingleOrDefaultAsync(u => u.UID == AuthenticatedUserId);
@@ -99,10 +102,8 @@ namespace MareSynchronosServer.Hubs
await Clients.All.SendAsync("UsersOnline",
await _dbContext.Users.CountAsync(u => !string.IsNullOrEmpty(u.CharacterIdentification)));
}
else
{
MareMetrics.UnauthorizedConnections.Dec();
}
MareMetrics.Connections.Dec();
await base.OnDisconnectedAsync(exception);
}