2026-08-10 15:16:09 +02:00
|
|
|
@* AgentMetrics.razor — jauge CPU / RAM / disque + uptime d'un agent.
|
|
|
|
|
Affiche les métriques live remontées par le heartbeat (nullable). *@
|
|
|
|
|
@using Heimdall.Web.Services
|
2026-10-25 05:59:18 +01:00
|
|
|
@inject UiText Text
|
2026-08-10 15:16:09 +02:00
|
|
|
|
|
|
|
|
@if (Agent is null)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["AgentMetrics_NoMetrics"]</MudText>
|
2026-08-10 15:16:09 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" sm="6" md="3">
|
|
|
|
|
<MetricTile Label="CPU" Value="@FormatCpu()" Color="Color.Primary"
|
|
|
|
|
Progress="@CpuPercent" ProgressColor="Color.Primary" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6" md="3">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MetricTile Label="@Text["AgentMetrics_Memory"]" Value="@FormatMemory()" Color="Color.Info"
|
2026-08-10 15:16:09 +02:00
|
|
|
Progress="@MemoryPercent" ProgressColor="Color.Info" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6" md="3">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MetricTile Label="@Text["AgentMetrics_Disk"]" Value="@FormatDisk()" Color="Color.Warning"
|
2026-08-10 15:16:09 +02:00
|
|
|
Progress="@DiskPercent" ProgressColor="Color.Warning" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6" md="3">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MetricTile Label="@Text["AgentMetrics_Uptime"]" Value="@FormatUptime()" Color="Color.Success"
|
2026-08-10 15:16:09 +02:00
|
|
|
Icon="@Icons.Material.Filled.Schedule" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
/// <summary>Agent whose live metrics are shown.</summary>
|
|
|
|
|
[Parameter, EditorRequired]
|
|
|
|
|
public AgentItem? Agent { get; set; }
|
|
|
|
|
|
|
|
|
|
private double? CpuPercent => Agent?.CpuUsagePercent is { } c ? Math.Clamp(c, 0, 100) : null;
|
|
|
|
|
private double? DiskPercent => Agent?.DiskUsagePercent is { } d ? Math.Clamp(d, 0, 100) : null;
|
|
|
|
|
|
|
|
|
|
private double? MemoryPercent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Agent is null || Agent.MemoryMb <= 0) return null;
|
|
|
|
|
var usedMb = Agent.MemoryUsageBytes is { } b ? b / 1024.0 / 1024.0 : 0;
|
|
|
|
|
return Math.Clamp(usedMb / Agent.MemoryMb * 100, 0, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string FormatCpu()
|
|
|
|
|
=> Agent?.CpuUsagePercent is { } c ? $"{c:F1} %" : "—";
|
|
|
|
|
|
|
|
|
|
private string FormatMemory()
|
|
|
|
|
{
|
|
|
|
|
if (Agent is null) return "—";
|
|
|
|
|
if (Agent.MemoryUsageBytes is { } b)
|
|
|
|
|
return $"{FormatMb(b)} / {Agent.MemoryMb} Mo";
|
|
|
|
|
return $"{Agent.MemoryMb} Mo";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string FormatDisk()
|
|
|
|
|
=> Agent?.DiskUsagePercent is { } d ? $"{d:F1} %" : "—";
|
|
|
|
|
|
|
|
|
|
private string FormatUptime()
|
|
|
|
|
{
|
|
|
|
|
if (Agent?.UptimeSeconds is not { } s) return "—";
|
|
|
|
|
var t = TimeSpan.FromSeconds(s);
|
2026-10-25 05:59:18 +01:00
|
|
|
return t.TotalDays >= 1 ? string.Format(Text["AgentMetrics_UptimeDays"], (int)t.TotalDays, t.Hours) : string.Format(Text["AgentMetrics_UptimeHours"], t.Hours, t.Minutes);
|
2026-08-10 15:16:09 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
private string FormatMb(long bytes)
|
2026-08-10 15:16:09 +02:00
|
|
|
=> bytes >= 1024 * 1024 * 1024 ? $"{bytes / 1024.0 / 1024.0 / 1024.0:F1} Go"
|
2026-10-25 05:59:18 +01:00
|
|
|
: bytes >= 1024 * 1024 ? string.Format(Text["AgentMetrics_Megabytes"], bytes / 1024.0 / 1024.0)
|
|
|
|
|
: string.Format(Text["AgentMetrics_Kilobytes"], bytes / 1024.0);
|
2026-08-10 15:16:09 +02:00
|
|
|
}
|