feat(ui): affiche les métriques live des agents (CPU, RAM, disque, uptime)

- AgentResponse expose CpuUsagePercent/MemoryUsageBytes/DiskUsagePercent/
  UptimeSeconds (mappés dans les 3 handlers GetAgent/GetAll/GetBySite)
- AgentItem client complété ; nouvelles tuiles AgentMetrics + MetricTile
  (jauges colorées) intégrées en ChildRowContent dans AllAgentsPage
This commit is contained in:
Arnaud Dartois committed 2026-08-10 15:16:09 +02:00
1 parent 2f3b3dd666
commit 6606cf9dd5
8 files changed
+132 -4

No files matched your search

@@ -27,5 +27,6 @@ public class GetAgentHandler : IRequestHandler<GetAgentQuery, ServiceResult<Agen
private static AgentResponse MapResponse(Domain.Entities.Agent a) => new(
a.Id, a.SiteId, a.Site?.Name ?? string.Empty, a.Name, a.Hostname, a.Version, a.Status,
a.LastHeartbeat, a.PublicIp, a.HasGpu, a.CpuCores, a.MemoryMb,
a.GpuType.ToString(), a.CreatedAt);
a.GpuType.ToString(), a.CreatedAt,
a.CpuUsagePercent, a.MemoryUsageBytes, a.DiskUsagePercent, a.UptimeSeconds);
}
@@ -37,5 +37,6 @@ public class GetAgentsBySiteHandler : IRequestHandler<GetAgentsBySiteQuery, Serv
private static AgentResponse MapResponse(Domain.Entities.Agent a) => new(
a.Id, a.SiteId, a.Site?.Name ?? string.Empty, a.Name, a.Hostname, a.Version, a.Status,
a.LastHeartbeat, a.PublicIp, a.HasGpu, a.CpuCores, a.MemoryMb,
a.GpuType.ToString(), a.CreatedAt);
a.GpuType.ToString(), a.CreatedAt,
a.CpuUsagePercent, a.MemoryUsageBytes, a.DiskUsagePercent, a.UptimeSeconds);
}
@@ -33,5 +33,6 @@ public class GetAllAgentsHandler : IRequestHandler<GetAllAgentsQuery, ServiceRes
private static AgentResponse MapResponse(Domain.Entities.Agent a) => new(
a.Id, a.SiteId, a.Site?.Name ?? string.Empty, a.Name, a.Hostname, a.Version, a.Status,
a.LastHeartbeat, a.PublicIp, a.HasGpu, a.CpuCores, a.MemoryMb,
a.GpuType.ToString(), a.CreatedAt);
a.GpuType.ToString(), a.CreatedAt,
a.CpuUsagePercent, a.MemoryUsageBytes, a.DiskUsagePercent, a.UptimeSeconds);
}
+5 -1
View File
@@ -34,7 +34,11 @@ public record AgentResponse(
int CpuCores,
long MemoryMb,
string GpuType,
DateTime CreatedAt);
DateTime CreatedAt,
double? CpuUsagePercent = null,
long? MemoryUsageBytes = null,
double? DiskUsagePercent = null,
long? UptimeSeconds = null);
public record RegisterAgentResponse(
Guid AgentId,
@@ -0,0 +1,73 @@
@* 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
@if (Agent is null)
{
<MudText Typo="Typo.body2" Color="Color.Secondary">Aucune métrique disponible.</MudText>
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">
<MetricTile Label="Mémoire" Value="@FormatMemory()" Color="Color.Info"
Progress="@MemoryPercent" ProgressColor="Color.Info" />
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MetricTile Label="Disque" Value="@FormatDisk()" Color="Color.Warning"
Progress="@DiskPercent" ProgressColor="Color.Warning" />
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MetricTile Label="Uptime" Value="@FormatUptime()" Color="Color.Success"
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);
return t.TotalDays >= 1 ? $"{(int)t.TotalDays}j {t.Hours}h" : $"{t.Hours}h {t.Minutes}min";
}
private static string FormatMb(long bytes)
=> bytes >= 1024 * 1024 * 1024 ? $"{bytes / 1024.0 / 1024.0 / 1024.0:F1} Go"
: bytes >= 1024 * 1024 ? $"{bytes / 1024.0 / 1024.0:F0} Mo"
: $"{bytes / 1024.0:F0} Ko";
}
@@ -0,0 +1,39 @@
@* MetricTile.razor — tuile de métrique compacte (label + valeur + jauge optionnelle). *@
@using MudBlazor
<MudPaper Elevation="1" Class="pa-3" Style="border-radius: 10px; height: 100%;">
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="d-flex align-center">
@if (Icon is not null)
{
<MudIcon Icon="@Icon" Size="Size.Small" Class="mr-1" />
}
@Label
</MudText>
<MudText Typo="Typo.h6" Class="mt-1 font-weight-bold" Style="@($"color:{ColorToCss(Color)}")">
@Value
</MudText>
@if (Progress is { } p)
{
<MudProgressLinear Value="@p" Color="@ProgressColor" Rounded="true" Size="Size.Small" Class="mt-2" />
}
</MudPaper>
@code {
[Parameter, EditorRequired] public string Label { get; set; } = "";
[Parameter, EditorRequired] public string Value { get; set; } = "—";
[Parameter] public Color Color { get; set; } = Color.Default;
[Parameter] public Color ProgressColor { get; set; } = Color.Primary;
[Parameter] public double? Progress { get; set; }
[Parameter] public string? Icon { get; set; }
private static string ColorToCss(Color color) => color switch
{
Color.Primary => "var(--mud-palette-primary)",
Color.Secondary => "var(--mud-palette-secondary)",
Color.Info => "var(--mud-palette-info)",
Color.Success => "var(--mud-palette-success)",
Color.Warning => "var(--mud-palette-warning)",
Color.Error => "var(--mud-palette-error)",
_ => "var(--mud-palette-text-primary)",
};
}
@@ -94,6 +94,11 @@ else
</MudTooltip>
</MudTd>
</RowTemplate>
<ChildRowContent>
<MudTd ColSpan="8">
<AgentMetrics Agent="@context" />
</MudTd>
</ChildRowContent>
</MudTable>
@* ─── Pagination ─── *@
@@ -524,6 +524,10 @@ public class AgentItem
public long MemoryMb { get; set; }
public string GpuType { get; set; } = "None";
public DateTime CreatedAt { get; set; }
public double? CpuUsagePercent { get; set; }
public long? MemoryUsageBytes { get; set; }
public double? DiskUsagePercent { get; set; }
public long? UptimeSeconds { get; set; }
}
// ─── Settings DTOs ────────────────────────────────────────────────