diff --git a/LightlessSyncServer/LightlessSyncServer/Services/SystemInfoService.cs b/LightlessSyncServer/LightlessSyncServer/Services/SystemInfoService.cs index 3895920..4dc39cf 100644 --- a/LightlessSyncServer/LightlessSyncServer/Services/SystemInfoService.cs +++ b/LightlessSyncServer/LightlessSyncServer/Services/SystemInfoService.cs @@ -7,7 +7,9 @@ using LightlessSyncShared.Services; using LightlessSyncShared.Utils.Configuration; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; +using StackExchange.Redis; using StackExchange.Redis.Extensions.Core.Abstractions; +using static LightlessSyncServer.Hubs.LightlessHub; namespace LightlessSyncServer.Services; @@ -52,7 +54,13 @@ public sealed class SystemInfoService : BackgroundService _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeAvailableIOWorkerThreads, ioThreads); var onlineUsers = (_redis.SearchKeysAsync("UID:*").GetAwaiter().GetResult()).Count(); - var lightfinderUsers = (_redis.SearchKeysAsync("broadcast:*").GetAwaiter().GetResult()).Count(); + + var allLightfinderKeys = _redis.SearchKeysAsync("broadcast:*").GetAwaiter().GetResult().Where(c => !c.Contains("owner", StringComparison.Ordinal)).ToHashSet(StringComparer.Ordinal); + var allLightfinderItems = _redis.GetAllAsync(allLightfinderKeys).GetAwaiter().GetResult(); + + var countLightFinderUsers = allLightfinderItems.Count; + var countLightFinderSyncshells = allLightfinderItems.Count(static l => string.IsNullOrEmpty(l.Value.GID)); + SystemInfoDto = new SystemInfoDto() { OnlineUsers = onlineUsers, @@ -67,11 +75,12 @@ public sealed class SystemInfoService : BackgroundService using var db = await _dbContextFactory.CreateDbContextAsync(ct).ConfigureAwait(false); _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeAuthorizedConnections, onlineUsers); - _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeLightfinderConnections, lightfinderUsers); + _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeLightFinderConnections, countLightFinderUsers); _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugePairs, db.ClientPairs.AsNoTracking().Count()); - _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugePairsPaused, db.Permissions.AsNoTracking().Where(p => p.IsPaused).Count()); + _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugePairsPaused, db.Permissions.AsNoTracking().Count(p => p.IsPaused)); _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeGroups, db.Groups.AsNoTracking().Count()); _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeGroupPairs, db.GroupPairs.AsNoTracking().Count()); + _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeLightFinderGroups, countLightFinderSyncshells); _lightlessMetrics.SetGaugeTo(MetricsAPI.GaugeUsersRegistered, db.Users.AsNoTracking().Count()); } diff --git a/LightlessSyncServer/LightlessSyncServer/Startup.cs b/LightlessSyncServer/LightlessSyncServer/Startup.cs index 452ad4c..3b9ba70 100644 --- a/LightlessSyncServer/LightlessSyncServer/Startup.cs +++ b/LightlessSyncServer/LightlessSyncServer/Startup.cs @@ -295,7 +295,8 @@ public class Startup }, new List { MetricsAPI.GaugeAuthorizedConnections, - MetricsAPI.GaugeLightfinderConnections, + MetricsAPI.GaugeLightFinderConnections, + MetricsAPI.GaugeLightFinderGroups, MetricsAPI.GaugeConnections, MetricsAPI.GaugePairs, MetricsAPI.GaugePairsPaused, diff --git a/LightlessSyncServer/LightlessSyncShared/Metrics/MetricsAPI.cs b/LightlessSyncServer/LightlessSyncShared/Metrics/MetricsAPI.cs index 9139a55..fe97f72 100644 --- a/LightlessSyncServer/LightlessSyncShared/Metrics/MetricsAPI.cs +++ b/LightlessSyncServer/LightlessSyncShared/Metrics/MetricsAPI.cs @@ -9,7 +9,8 @@ public class MetricsAPI public const string GaugeAvailableIOWorkerThreads = "lightless_available_threadpool_io"; public const string GaugeUsersRegistered = "lightless_users_registered"; public const string CounterUsersRegisteredDeleted = "lightless_users_registered_deleted"; - public const string GaugeLightfinderConnections = "lightless_lightfinder_connections"; + public const string GaugeLightFinderConnections = "lightless_lightfinder_connections"; + public const string GaugeLightFinderGroups = "lightless_lightfinder_groups"; public const string GaugePairs = "lightless_pairs"; public const string GaugePairsPaused = "lightless_pairs_paused"; public const string GaugeFilesTotal = "lightless_files";