lock metrics calls
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user