add threadpool info to statistics, change systeminfo to grab online users from db instead of metrics

This commit is contained in:
Stanley Dimant
2022-08-08 11:27:57 +02:00
parent 30b86b71a9
commit ef70dd5882
2 changed files with 19 additions and 2 deletions

View File

@@ -14,6 +14,8 @@ namespace MareSynchronosServer.Metrics
new(Prometheus.Metrics.CreateGauge("mare_unauthorized_connections", "Unauthorized Connections"));
public static readonly LockedProxyGauge AuthorizedConnections =
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"));

View File

@@ -1,10 +1,13 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MareSynchronos.API;
using MareSynchronosServer.Data;
using MareSynchronosServer.Hubs;
using MareSynchronosServer.Metrics;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
@@ -12,13 +15,15 @@ namespace MareSynchronosServer;
public class SystemInfoService : IHostedService, IDisposable
{
private readonly IServiceProvider _services;
private readonly ILogger<SystemInfoService> _logger;
private readonly IHubContext<MareHub> _hubContext;
private Timer _timer;
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;
_hubContext = hubContext;
}
@@ -34,6 +39,16 @@ public class SystemInfoService : IHostedService, IDisposable
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()
{
CacheUsage = 0,
@@ -41,7 +56,7 @@ public class SystemInfoService : IHostedService, IDisposable
RAMUsage = 0,
NetworkIn = 0,
NetworkOut = 0,
OnlineUsers = (int)MareMetrics.AuthorizedConnections.Value,
OnlineUsers = users,
UploadedFiles = 0
};