add threadpool info to statistics, change systeminfo to grab online users from db instead of metrics
This commit is contained in:
@@ -14,6 +14,8 @@ namespace MareSynchronosServer.Metrics
|
|||||||
new(Prometheus.Metrics.CreateGauge("mare_unauthorized_connections", "Unauthorized Connections"));
|
new(Prometheus.Metrics.CreateGauge("mare_unauthorized_connections", "Unauthorized Connections"));
|
||||||
public static readonly LockedProxyGauge AuthorizedConnections =
|
public static readonly LockedProxyGauge AuthorizedConnections =
|
||||||
new(Prometheus.Metrics.CreateGauge("mare_authorized_connections", "Authorized Connections"));
|
new(Prometheus.Metrics.CreateGauge("mare_authorized_connections", "Authorized Connections"));
|
||||||
|
public static readonly LockedProxyGauge AvailableWorkerThreads = new(Prometheus.Metrics.CreateGauge("mare_available_threadpool", "Available Threadpool Workers"));
|
||||||
|
public static readonly LockedProxyGauge AvailableIOWorkerThreads = new(Prometheus.Metrics.CreateGauge("mare_available_threadpool_io", "Available Threadpool IO Workers"));
|
||||||
|
|
||||||
public static readonly LockedProxyGauge UsersRegistered = new(Prometheus.Metrics.CreateGauge("mare_users_registered", "Total Registrations"));
|
public static readonly LockedProxyGauge UsersRegistered = new(Prometheus.Metrics.CreateGauge("mare_users_registered", "Total Registrations"));
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MareSynchronos.API;
|
using MareSynchronos.API;
|
||||||
|
using MareSynchronosServer.Data;
|
||||||
using MareSynchronosServer.Hubs;
|
using MareSynchronosServer.Hubs;
|
||||||
using MareSynchronosServer.Metrics;
|
using MareSynchronosServer.Metrics;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
@@ -12,13 +15,15 @@ namespace MareSynchronosServer;
|
|||||||
|
|
||||||
public class SystemInfoService : IHostedService, IDisposable
|
public class SystemInfoService : IHostedService, IDisposable
|
||||||
{
|
{
|
||||||
|
private readonly IServiceProvider _services;
|
||||||
private readonly ILogger<SystemInfoService> _logger;
|
private readonly ILogger<SystemInfoService> _logger;
|
||||||
private readonly IHubContext<MareHub> _hubContext;
|
private readonly IHubContext<MareHub> _hubContext;
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
||||||
|
|
||||||
public SystemInfoService(ILogger<SystemInfoService> logger, IHubContext<MareHub> hubContext)
|
public SystemInfoService(IServiceProvider services, ILogger<SystemInfoService> logger, IHubContext<MareHub> hubContext)
|
||||||
{
|
{
|
||||||
|
_services = services;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_hubContext = hubContext;
|
_hubContext = hubContext;
|
||||||
}
|
}
|
||||||
@@ -34,6 +39,16 @@ public class SystemInfoService : IHostedService, IDisposable
|
|||||||
|
|
||||||
private void PushSystemInfo(object state)
|
private void PushSystemInfo(object state)
|
||||||
{
|
{
|
||||||
|
ThreadPool.GetAvailableThreads(out int workerThreads, out int ioThreads);
|
||||||
|
_logger.LogInformation($"ThreadPool: {workerThreads} workers available, {ioThreads} IO workers available");
|
||||||
|
MareMetrics.AvailableWorkerThreads.Set(workerThreads);
|
||||||
|
MareMetrics.AvailableIOWorkerThreads.Set(ioThreads);
|
||||||
|
|
||||||
|
using var scope = _services.CreateScope();
|
||||||
|
var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||||
|
|
||||||
|
var users = db.Users.Count(c => c.CharacterIdentification != null);
|
||||||
|
|
||||||
SystemInfoDto = new SystemInfoDto()
|
SystemInfoDto = new SystemInfoDto()
|
||||||
{
|
{
|
||||||
CacheUsage = 0,
|
CacheUsage = 0,
|
||||||
@@ -41,7 +56,7 @@ public class SystemInfoService : IHostedService, IDisposable
|
|||||||
RAMUsage = 0,
|
RAMUsage = 0,
|
||||||
NetworkIn = 0,
|
NetworkIn = 0,
|
||||||
NetworkOut = 0,
|
NetworkOut = 0,
|
||||||
OnlineUsers = (int)MareMetrics.AuthorizedConnections.Value,
|
OnlineUsers = users,
|
||||||
UploadedFiles = 0
|
UploadedFiles = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user