81 lines
2.6 KiB
Plaintext
81 lines
2.6 KiB
Plaintext
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
|
|
|
@implements IDisposable
|
|
|
|
@inject HttpApiClient HttpApiClient
|
|
|
|
<LazyLoader Load="Load">
|
|
<div class="mt-5">
|
|
@if (IsOffline)
|
|
{
|
|
<IconAlert Icon="bi bi-database-x"
|
|
Color="text-red-500"
|
|
Title="Unable to fetch the node status"
|
|
Description="We were unable to fetch the node status. Please check if the node is online and the daemon running">
|
|
</IconAlert>
|
|
}
|
|
else
|
|
{
|
|
var cpuUsage = Math.Round(Status.CpuUsage.Average(x => x), 2) + "%";
|
|
var memoryUsage = $"{Formatter.FormatSize((long)(Status.MemoryTotal - Status.MemoryAvailable))} / {Formatter.FormatSize((long)Status.MemoryTotal)}";
|
|
var uptime = Formatter.FormatUptime(Status.Uptime);
|
|
var diskUsage = $"{Formatter.FormatSize((long)Status.DiskFree)} / {Formatter.FormatSize((long)Status.DiskTotal)}";
|
|
|
|
<div class="mt-5 gap-5 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4">
|
|
<StatCard Title="CPU Model" Text="@Status.CpuModel" Icon="bi bi-cpu"/>
|
|
<StatCard Title="CPU Usage" Text="@cpuUsage" Icon="bi bi-speedometer2"/>
|
|
<StatCard Title="Memory Usage" Text="@memoryUsage" Icon="bi bi-memory"/>
|
|
<StatCard Title="Host OS" Text="Arch Linux" Icon="bi bi-motherboard"/>
|
|
<StatCard Title="Uptime" Text="@uptime" Icon="bi bi-clock-history"/>
|
|
<StatCard Title="Containers" Text="11" Icon="bi bi-box-seam"/>
|
|
<StatCard Title="Disk Usage" Text="@diskUsage" Icon="bi bi-hdd"/>
|
|
<StatCard Title="Version" Text="v2.1 - Galaxy (Release #1)" Icon="bi bi-tag"/>
|
|
</div>
|
|
}
|
|
</div>
|
|
</LazyLoader>
|
|
|
|
@code
|
|
{
|
|
[Parameter] public int NodeId { get; set; }
|
|
|
|
private bool IsOffline = false;
|
|
private bool KeepRefreshing = true;
|
|
|
|
private StatusNodeResponse Status;
|
|
|
|
private async Task Load(LazyLoader arg)
|
|
{
|
|
await UpdateStatus();
|
|
|
|
Task.Run(async () =>
|
|
{
|
|
while (KeepRefreshing)
|
|
{
|
|
await UpdateStatus();
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
|
}
|
|
});
|
|
}
|
|
|
|
private async Task UpdateStatus()
|
|
{
|
|
IsOffline = false;
|
|
|
|
try
|
|
{
|
|
Status = await HttpApiClient.GetJson<StatusNodeResponse>($"admin/servers/nodes/{NodeId}/status");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
IsOffline = true;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
KeepRefreshing = false;
|
|
}
|
|
} |