@* 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 @inject UiText Text @if (Agent is null) { @Text["AgentMetrics_NoMetrics"] return; } @code { /// Agent whose live metrics are shown. [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 ? string.Format(Text["AgentMetrics_UptimeDays"], (int)t.TotalDays, t.Hours) : string.Format(Text["AgentMetrics_UptimeHours"], t.Hours, t.Minutes); } private string FormatMb(long bytes) => bytes >= 1024 * 1024 * 1024 ? $"{bytes / 1024.0 / 1024.0 / 1024.0:F1} Go" : bytes >= 1024 * 1024 ? string.Format(Text["AgentMetrics_Megabytes"], bytes / 1024.0 / 1024.0) : string.Format(Text["AgentMetrics_Kilobytes"], bytes / 1024.0); }