feat(inventory): add metric history dashboards
Heimdall Gitea / Build and tests (pull_request) Failing after 3m28s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and tests (pull_request) Failing after 3m28s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
This commit is contained in:
1 parent
9cf995383f
commit
c8c84f0e2c
24 files changed
+841
-1
No files matched your search
@@ -585,6 +585,39 @@ else
|
||||
}
|
||||
</SectionCard>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
||||
<div class="d-flex flex-wrap justify-space-between align-center mb-4">
|
||||
<MudText Typo="Typo.h6">Historique des ressources</MudText>
|
||||
<MudButtonGroup Variant="Variant.Outlined" Color="Color.Primary">
|
||||
<MudButton OnClick="@(() => LoadMetricHistoryAsync("24h"))" Disabled="@(_metricHistoryLoading || _metricRange == "24h")">24 h</MudButton>
|
||||
<MudButton OnClick="@(() => LoadMetricHistoryAsync("7d"))" Disabled="@(_metricHistoryLoading || _metricRange == "7d")">7 jours</MudButton>
|
||||
</MudButtonGroup>
|
||||
</div>
|
||||
@if (_metricHistoryLoading)
|
||||
{
|
||||
<MudProgressLinear Indeterminate="true" />
|
||||
}
|
||||
else if (_metricHistoryError)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error">Impossible de charger l’historique des ressources.</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (_metricHistory.LastOrDefault(point => point.InventoryObservedAtUtc.HasValue) is { } inventoryPoint)
|
||||
{
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mb-3">
|
||||
Dernier inventaire GPU/température reçu : @inventoryPoint.InventoryObservedAtUtc!.Value.ToLocalTime().ToString("g").
|
||||
</MudText>
|
||||
}
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="CPU utilisé" Points="@MetricSeries(point => point.CpuUsagePercent)" Minimum="0" Maximum="100" /></MudItem>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="Mémoire système utilisée" Points="@MetricSeries(MemoryUsedPercent)" Minimum="0" Maximum="100" /></MudItem>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="Disque utilisé" Points="@MetricSeries(point => point.DiskUsagePercent)" Minimum="0" Maximum="100" /></MudItem>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="Température GPU moyenne" Points="@MetricSeries(point => point.GpuTemperatureCelsius)" Unit=" °C" /></MudItem>
|
||||
</MudGrid>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@* ─── Agent Logs ─── *@
|
||||
<SectionCard Title="Logs"
|
||||
Icon="@Icons.Material.Filled.ReceiptLong"
|
||||
@@ -808,6 +841,10 @@ else
|
||||
|
||||
private AgentItem? _agent;
|
||||
private bool _loading = true;
|
||||
private List<AgentMetricHistoryPoint> _metricHistory = [];
|
||||
private bool _metricHistoryLoading;
|
||||
private bool _metricHistoryError;
|
||||
private string _metricRange = "24h";
|
||||
|
||||
// Updates
|
||||
private LatestReleaseInfo? _updateInfo;
|
||||
@@ -856,6 +893,7 @@ else
|
||||
_agent = await Api.GetAgentAsync(Id);
|
||||
if (_agent is not null)
|
||||
{
|
||||
await LoadMetricHistoryAsync(_metricRange);
|
||||
await LoadSettingsAsync();
|
||||
await LoadLogsAsync(keepPage: false);
|
||||
_ = LoadUpdateInfoAsync();
|
||||
@@ -865,6 +903,31 @@ else
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
private async Task LoadMetricHistoryAsync(string range)
|
||||
{
|
||||
_metricRange = range;
|
||||
_metricHistoryLoading = true;
|
||||
_metricHistoryError = false;
|
||||
try
|
||||
{
|
||||
_metricHistory = await Api.GetAgentMetricHistoryAsync(Id, range) ?? [];
|
||||
}
|
||||
catch
|
||||
{
|
||||
_metricHistoryError = true;
|
||||
_metricHistory = [];
|
||||
}
|
||||
finally { _metricHistoryLoading = false; }
|
||||
}
|
||||
|
||||
private List<MetricChartPoint> MetricSeries(Func<AgentMetricHistoryPoint, double?> selector)
|
||||
=> _metricHistory.Select(point => new MetricChartPoint(point.TimestampUtc, selector(point))).ToList();
|
||||
|
||||
private static double? MemoryUsedPercent(AgentMetricHistoryPoint point)
|
||||
=> point.MemoryUsedBytes is { } used && point.MemoryTotalBytes is > 0
|
||||
? Math.Clamp(100d * used / point.MemoryTotalBytes.Value, 0, 100)
|
||||
: null;
|
||||
|
||||
private async Task LoadSettingsAsync()
|
||||
{
|
||||
_settingsError = false;
|
||||
|
||||
@@ -45,6 +45,56 @@ else
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
||||
<div class="d-flex flex-wrap justify-space-between align-center mb-4">
|
||||
<MudText Typo="Typo.h6">Capacité et ressources du site</MudText>
|
||||
<MudButtonGroup Variant="Variant.Outlined" Color="Color.Primary">
|
||||
<MudButton OnClick="@(() => LoadCapacityHistoryAsync("24h"))" Disabled="@(_capacityHistoryLoading || _capacityRange == "24h")">24 h</MudButton>
|
||||
<MudButton OnClick="@(() => LoadCapacityHistoryAsync("7d"))" Disabled="@(_capacityHistoryLoading || _capacityRange == "7d")">7 jours</MudButton>
|
||||
</MudButtonGroup>
|
||||
</div>
|
||||
@if (_capacityHistoryLoading)
|
||||
{
|
||||
<MudProgressLinear Indeterminate="true" />
|
||||
}
|
||||
else if (_capacityHistoryError)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error">Impossible de charger l’historique de capacité.</MudAlert>
|
||||
}
|
||||
else if (_capacityHistory.Count == 0 || !_capacityHistory.Any(point => point.ReportingAgents > 0))
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">Les données historiques apparaîtront après le premier échantillon d’agent.</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
var latestCapacity = _capacityHistory.LastOrDefault(point => point.ReportingAgents > 0);
|
||||
@if (latestCapacity is not null)
|
||||
{
|
||||
@if (latestCapacity.InventoryObservedAtUtc.HasValue)
|
||||
{
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mb-2">
|
||||
Dernier inventaire GPU/température reçu : @latestCapacity.InventoryObservedAtUtc.Value.ToLocalTime().ToString("g").
|
||||
</MudText>
|
||||
}
|
||||
<MudGrid Class="mb-3">
|
||||
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">Agents échantillonnés</MudText><MudText Typo="Typo.h6">@latestCapacity.ReportingAgents</MudText></MudItem>
|
||||
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">Cœurs logiques</MudText><MudText Typo="Typo.h6">@(latestCapacity.LogicalCores?.ToString() ?? "—")</MudText></MudItem>
|
||||
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">RAM totale</MudText><MudText Typo="Typo.h6">@FormatCapacity(latestCapacity.MemoryCapacityBytes)</MudText></MudItem>
|
||||
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">RAM utilisée</MudText><MudText Typo="Typo.h6">@FormatCapacity(latestCapacity.MemoryUsedBytes)</MudText></MudItem>
|
||||
</MudGrid>
|
||||
}
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="CPU moyen utilisé" Points="@CapacitySeries(point => point.AverageCpuUsagePercent)" Minimum="0" Maximum="100" /></MudItem>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="Mémoire système utilisée" Points="@CapacitySeries(MemoryCapacityUsedPercent)" Minimum="0" Maximum="100" /></MudItem>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="Disque moyen utilisé" Points="@CapacitySeries(point => point.AverageDiskUsagePercent)" Minimum="0" Maximum="100" /></MudItem>
|
||||
<MudItem xs="12" md="6"><MetricHistoryChart Title="Température GPU moyenne" Points="@CapacitySeries(point => point.AverageGpuTemperatureCelsius)" Unit=" °C" /></MudItem>
|
||||
</MudGrid>
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-2">
|
||||
Les trous représentent des périodes sans échantillon en ligne; ils ne comptent pas comme une utilisation nulle.
|
||||
</MudText>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@* Token d'enregistrement *@
|
||||
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
||||
<MudText Typo="Typo.h6" Class="mb-4">
|
||||
@@ -196,6 +246,10 @@ else
|
||||
|
||||
private SiteItem? _site;
|
||||
private bool _loading = true;
|
||||
private List<SiteCapacityHistoryPoint> _capacityHistory = [];
|
||||
private bool _capacityHistoryLoading;
|
||||
private bool _capacityHistoryError;
|
||||
private string _capacityRange = "24h";
|
||||
private bool _generating;
|
||||
private string? _generatedToken;
|
||||
private DateTime _tokenExpiresAt;
|
||||
@@ -216,6 +270,8 @@ else
|
||||
try
|
||||
{
|
||||
_site = await Api.GetSiteAsync(Id);
|
||||
if (_site is not null)
|
||||
await LoadCapacityHistoryAsync(_capacityRange);
|
||||
}
|
||||
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
||||
finally { _loading = false; }
|
||||
@@ -223,6 +279,47 @@ else
|
||||
await LoadCredentials();
|
||||
}
|
||||
|
||||
private async Task LoadCapacityHistoryAsync(string range)
|
||||
{
|
||||
_capacityRange = range;
|
||||
_capacityHistoryLoading = true;
|
||||
_capacityHistoryError = false;
|
||||
try
|
||||
{
|
||||
_capacityHistory = await Api.GetSiteCapacityHistoryAsync(Id, range) ?? [];
|
||||
}
|
||||
catch
|
||||
{
|
||||
_capacityHistoryError = true;
|
||||
_capacityHistory = [];
|
||||
}
|
||||
finally { _capacityHistoryLoading = false; }
|
||||
}
|
||||
|
||||
private List<MetricChartPoint> CapacitySeries(Func<SiteCapacityHistoryPoint, double?> selector)
|
||||
=> _capacityHistory.Select(point => new MetricChartPoint(point.TimestampUtc, selector(point))).ToList();
|
||||
|
||||
private static double? MemoryCapacityUsedPercent(SiteCapacityHistoryPoint point)
|
||||
=> point.MemoryUsedBytes is { } used && point.MemoryCapacityBytes is > 0
|
||||
? Math.Clamp(100d * used / point.MemoryCapacityBytes.Value, 0, 100)
|
||||
: null;
|
||||
|
||||
private static string FormatCapacity(long? bytes)
|
||||
=> bytes is { } value ? FormatBytes(value) : "—";
|
||||
|
||||
private static string FormatBytes(long bytes)
|
||||
{
|
||||
string[] units = ["B", "KB", "MB", "GB", "TB"];
|
||||
var size = (double)bytes;
|
||||
var unit = 0;
|
||||
while (size >= 1024 && unit < units.Length - 1)
|
||||
{
|
||||
size /= 1024;
|
||||
unit++;
|
||||
}
|
||||
return $"{size:0.#} {units[unit]}";
|
||||
}
|
||||
|
||||
private async Task LoadCredentials()
|
||||
{
|
||||
_credentialsLoading = true;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<MudPaper Elevation="0" Class="pa-3" Style="border: 1px solid var(--mud-palette-lines-default); border-radius: 8px; height: 100%;">
|
||||
<MudText Typo="Typo.subtitle2">@Title</MudText>
|
||||
@if (Points.Count == 0 || !Points.Any(point => point.Value.HasValue))
|
||||
{
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-4">Aucune donnée sur cette période.</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<svg viewBox="0 0 720 160" role="img" aria-label="@Title" style="width:100%;height:150px;overflow:visible;">
|
||||
<line x1="40" y1="14" x2="710" y2="14" stroke="var(--mud-palette-lines-default)" />
|
||||
<line x1="40" y1="130" x2="710" y2="130" stroke="var(--mud-palette-lines-default)" />
|
||||
<text x="2" y="18" fill="var(--mud-palette-text-secondary)" font-size="11">@FormatValue(UpperBound)</text>
|
||||
<text x="2" y="134" fill="var(--mud-palette-text-secondary)" font-size="11">@FormatValue(LowerBound)</text>
|
||||
@foreach (var segment in GetSegments())
|
||||
{
|
||||
<polyline points="@segment" fill="none" stroke="var(--mud-palette-primary)" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" />
|
||||
}
|
||||
</svg>
|
||||
<div class="d-flex justify-space-between">
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary">@Points[0].TimestampUtc.ToLocalTime().ToString("g")</MudText>
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary">@Points[^1].TimestampUtc.ToLocalTime().ToString("g")</MudText>
|
||||
</div>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public string Title { get; set; } = "";
|
||||
[Parameter, EditorRequired] public IReadOnlyList<MetricChartPoint> Points { get; set; } = [];
|
||||
[Parameter] public string Unit { get; set; } = "%";
|
||||
[Parameter] public double? Minimum { get; set; }
|
||||
[Parameter] public double? Maximum { get; set; }
|
||||
|
||||
private double LowerBound
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Minimum.HasValue) return Minimum.Value;
|
||||
var values = Points.Where(point => point.Value.HasValue).Select(point => point.Value!.Value).ToArray();
|
||||
return values.Length == 0 ? 0 : Math.Floor(values.Min());
|
||||
}
|
||||
}
|
||||
|
||||
private double UpperBound
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Maximum.HasValue) return Maximum.Value;
|
||||
var values = Points.Where(point => point.Value.HasValue).Select(point => point.Value!.Value).ToArray();
|
||||
if (values.Length == 0) return 1;
|
||||
var max = Math.Ceiling(values.Max());
|
||||
return max <= LowerBound ? LowerBound + 1 : max;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetSegments()
|
||||
{
|
||||
const double left = 40;
|
||||
const double right = 710;
|
||||
const double top = 14;
|
||||
const double bottom = 130;
|
||||
var span = Math.Max(UpperBound - LowerBound, double.Epsilon);
|
||||
var segment = new List<string>();
|
||||
for (var index = 0; index < Points.Count; index++)
|
||||
{
|
||||
if (Points[index].Value is not { } value)
|
||||
{
|
||||
if (segment.Count > 0) { yield return string.Join(" ", segment); segment.Clear(); }
|
||||
continue;
|
||||
}
|
||||
|
||||
var x = Points.Count <= 1 ? left : left + (right - left) * index / (Points.Count - 1);
|
||||
var y = bottom - (bottom - top) * (value - LowerBound) / span;
|
||||
segment.Add($"{x.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture)},{y.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture)}");
|
||||
}
|
||||
if (segment.Count > 0) yield return string.Join(" ", segment);
|
||||
}
|
||||
|
||||
private string FormatValue(double value) => $"{value:0.##}{Unit}";
|
||||
}
|
||||
Reference in new issue
Block a user