diff --git a/Moonlight/Core/UI/Components/ColoredBar.razor b/Moonlight/Core/UI/Components/ColoredBar.razor new file mode 100644 index 0000000..88ffbbe --- /dev/null +++ b/Moonlight/Core/UI/Components/ColoredBar.razor @@ -0,0 +1,26 @@ +@{ + var color = "primary"; + + if (Value >= PrimaryEnd && Value < DangerStart) + color = "warning"; + + if (Value >= DangerStart) + color = "danger"; + + var percent = Math.Round(Value); + var percentText = Math.Round(Value, 2) + "%"; +} + +
+
+
+
+ +@code +{ + [Parameter] + public double Value { get; set; } + + [Parameter] public double PrimaryEnd { get; set; } = 60; + [Parameter] public double DangerStart { get; set; } = 80; +} diff --git a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor index c951ffb..0ca4b9d 100644 --- a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor +++ b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor @@ -4,52 +4,153 @@ @using Moonlight.Features.Servers.UI.Components @using Moonlight.Features.Servers.Entities @using MoonCore.Abstractions -@using BlazorTable @using Microsoft.EntityFrameworkCore @using MoonCore.Exceptions @using MoonCore.Helpers @using System.Text.RegularExpressions; +@using Moonlight.Features.Servers.Api.Resources +@using Moonlight.Features.Servers.Services @inject Repository ServerRepository @inject Repository NodeRepository +@inject NodeService NodeService +@inject IServiceProvider ServiceProvider + +@implements IDisposable @attribute [RequirePermission(5001)] - - - - - - - - - - - - - - - - - Add a new node in order to get started. Need help? Check out our documentation - - - + + + + + + + + + + + + + + + + + + + + + + + + Add a new node in order to get started. Need help? Check out our documentation + + + + @code { - private ServerNode[] Load(Repository repository) + private Timer UpdateTimer; + private Dictionary NodeStats = new(); + + private Task Load(LazyLoader lazyLoader) + { + UpdateTimer = new(async _ => + { + NodeStats.Clear(); + + using var scope = ServiceProvider.CreateScope(); + var nodeRepo = scope.ServiceProvider.GetRequiredService>(); + var nodes = nodeRepo.Get().ToArray(); + + foreach (var node in nodes) + { + try + { + var status = await NodeService.GetStatus(node); + + NodeStats[node.Id] = status; + } + catch (Exception e) + { + Logger.Warn($"Unable to fetch system status for node '{node.Name}'"); + Logger.Warn(e); + + NodeStats[node.Id] = null; + } + + await InvokeAsync(StateHasChanged); + } + }, null, TimeSpan.Zero, TimeSpan.FromSeconds(1)); + + return Task.CompletedTask; + } + + private ServerNode[] LoadData(Repository repository) { return repository .Get() @@ -106,4 +207,9 @@ return false; } + + public void Dispose() + { + UpdateTimer?.Dispose(); + } } \ No newline at end of file