117 lines
3.8 KiB
Plaintext
117 lines
3.8 KiB
Plaintext
@using System.Text.Json
|
|
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
|
|
|
@implements IDisposable
|
|
|
|
@inject HttpApiClient HttpApiClient
|
|
|
|
<LazyLoader Load="Load">
|
|
<div class="mt-8">
|
|
@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
|
|
{
|
|
@*
|
|
<div class="mt-8 mb-4">
|
|
<h2 class="text-base font-semibold leading-7 text-slate-100">
|
|
Node overview
|
|
</h2>
|
|
<p class="mt-1 text-sm leading-6 text-slate-400">
|
|
See all important details of this node at one quick look
|
|
</p>
|
|
</div>
|
|
*@
|
|
|
|
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.DiskTotal - 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 class="my-4">
|
|
<h2 class="text-base font-semibold leading-7 text-slate-100">
|
|
CPU Cores
|
|
</h2>
|
|
<p class="mt-1 text-sm leading-6 text-slate-400">
|
|
View the nodes cpu usage in detail
|
|
</p>
|
|
</div>
|
|
|
|
<div class="mt-5 gap-5 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5">
|
|
@{
|
|
int index = 1;
|
|
}
|
|
|
|
@foreach (var usage in Status.CpuUsage)
|
|
{
|
|
<ProgressStatCard Title="@("Core #" + index)" CurrentValue="@usage" MaxValue="100"></ProgressStatCard>
|
|
|
|
index++;
|
|
}
|
|
</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");
|
|
|
|
Console.WriteLine(JsonSerializer.Serialize(Status));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
IsOffline = true;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
KeepRefreshing = false;
|
|
}
|
|
} |