## Contexte Implémentation des tickets #82, #83, #84, #85 — télémétrie inventaire matériel agent. L'objectif est de fournir au central un maximum d'informations sur les machines des agents (CPU, mémoire, disques, GPU, OS, réseau, conteneur) sans SSH. ## Changements ### Nouveaux collecteurs (src/Heimdall.Agent/Services/) - **CpuInfoProvider** : parse `/proc/cpuinfo` (vendor, modèle, cœurs physiques/logiques, fréquence, flags AVX/AVX2/FMA/AVX512, cache), topologie, détection cgroup CPU (`/sys/fs/cgroup/cpu.max` v2) - **DiskInventoryProvider** : énumère les montages (`/proc/mounts`), capacité/libre/type SSD/HDD via `/sys/block/*/queue/rotation` - **GpuInventoryProvider** : nvidia-smi, sysfs DRM, vainfo, rocm-smi avec fallback silencieux, multi-GPU - **HostInfoProvider** : os-release, uname, `/proc/uptime` (uptime machine ≠ process), températures sysfs - **ContainerInfoProvider** : détection Docker (/.dockerenv, cgroup), ID conteneur, limites CPU/mémoire ### Refonte SystemMetricsProvider - Séparation host vs process (RAM machine ≠ RAM conteneur ≠ WorkingSet64) - Uptime machine (`/proc/uptime`) distinct de l'uptime process - Mémoire swap ### Entité Agent + Migration - Champs structurés CPU/mémoire/disque/GPU/OS/réseau (tous nullable, rétrocompatible) - Migration EF `AddAgentTelemetryInventory` ### Transport heartbeat - Inventaire au register + refresh périodique (5 min, pas à chaque tick) - Champs JSON pour listes (disques, GPU, interfaces réseau, températures) ### UI Admin (AgentDetail.razor) - Sections CPU, Mémoire/Disques, GPU, Machine/Conteneur avec barres de progression et badges ### Tests - 40+ tests unitaires : providers, handlers, entité Agent - Total : 999 tests verts (Domain 149, Application 397, Agent 210, Web 243) ## Tickets liés - Fixes #82 — CPU inventory - Fixes #83 — Mémoire & disque - Fixes #84 — GPU inventory - Fixes #85 — OS, conteneur, réseau ## Résultats des tests - `dotnet build` : 0 erreur, 0 warning - Domain.Tests : 149 passed - Application.Tests : 397 passed - Agent.Tests : 210 passed - Web.Tests : 243 passed - Total : 999 tests ✅ ## Checklist - [x] `dotnet build` vert (TreatWarningsAsErrors) - [x] Tests unitaires verts - [x] Migration EF créée - [x] Champs nullable (rétrocompatible) - [x] Pas de référence Infrastructure dans les contrôleurs - [x] Collecteurs avec fallback silencieux (pas de crash sans GPU/Docker/sysfs) Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/137
170 lines
6.8 KiB
Plaintext
170 lines
6.8 KiB
Plaintext
@namespace Heimdall.Web.Components.Settings
|
|
@inject HeimdallApiClient Api
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-lg);">
|
|
<div class="d-flex align-center mb-3">
|
|
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
|
<i class="fas fa-database mr-2"></i> Stockage
|
|
</MudText>
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary">@_provider</MudChip>
|
|
</div>
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
|
|
Choisissez le mode de stockage des snapshots et enregistrements : disque local (« Fichier ») ou objet S3 (Alarik/MinIO).
|
|
</MudText>
|
|
|
|
<MudGrid>
|
|
<MudItem xs="12" md="6">
|
|
<MudSelect T="string" Label="Provider" Variant="Variant.Outlined" Value="@_provider" ValueChanged="async v => await SaveProviderAsync(v)" Immediate="true">
|
|
<MudSelectItem T="string" Value="@("Local")">Fichier (disque local)</MudSelectItem>
|
|
<MudSelectItem T="string" Value="@("S3")">S3 (Alarik / MinIO)</MudSelectItem>
|
|
</MudSelect>
|
|
</MudItem>
|
|
|
|
@if (_provider == "Local")
|
|
{
|
|
<MudItem xs="12">
|
|
<MudTextField T="string" Label="Chemin racine" Variant="Variant.Outlined"
|
|
Value="@GetValue("storage.local.path")"
|
|
ValueChanged="OnLocalPathChanged"
|
|
HelperText="Dossier local où sont écrits snapshots et enregistrements." />
|
|
</MudItem>
|
|
}
|
|
else
|
|
{
|
|
<MudItem xs="12" md="6">
|
|
<MudTextField T="string" Label="Endpoint S3" Variant="Variant.Outlined"
|
|
Value="@GetValue("storage.s3.endpoint")"
|
|
ValueChanged="OnEndpointChanged"
|
|
HelperText="Ex : http://alarik:9000" />
|
|
</MudItem>
|
|
<MudItem xs="12" md="6">
|
|
<MudTextField T="string" Label="Bucket" Variant="Variant.Outlined"
|
|
Value="@GetValue("storage.s3.bucket")"
|
|
ValueChanged="OnBucketChanged" />
|
|
</MudItem>
|
|
<MudItem xs="12" md="6">
|
|
<MudTextField T="string" Label="Clé d'accès" Variant="Variant.Outlined"
|
|
Value="@GetValue("storage.s3.accessKey")"
|
|
ValueChanged="OnAccessKeyChanged" />
|
|
</MudItem>
|
|
<MudItem xs="12" md="6">
|
|
<MudTextField T="string" Label="Clé secrète" Variant="Variant.Outlined"
|
|
Value="@GetValue("storage.s3.secretKey")" Type="InputType.Password"
|
|
ValueChanged="OnSecretKeyChanged" />
|
|
</MudItem>
|
|
<MudItem xs="12" md="6">
|
|
<MudTextField T="string" Label="Région" Variant="Variant.Outlined"
|
|
Value="@GetValue("storage.s3.region")"
|
|
ValueChanged="OnRegionChanged" />
|
|
</MudItem>
|
|
}
|
|
</MudGrid>
|
|
|
|
<div class="d-flex align-center mt-3">
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.VerifiedUser"
|
|
OnClick="@TestAsync" Disabled="@_testing">
|
|
@(_testing ? "Test en cours…" : "Tester la connexion")
|
|
</MudButton>
|
|
@if (_testResult is not null)
|
|
{
|
|
<MudChip T="string" Size="Size.Small" Class="ml-3"
|
|
Color="@(_testResult.Healthy == true ? Color.Success : Color.Error)" Variant="Variant.Outlined">
|
|
@GetStorageTestStatus()
|
|
</MudChip>
|
|
}
|
|
</div>
|
|
</MudPaper>
|
|
|
|
@code {
|
|
private List<AppSettingItem> _settings = [];
|
|
private string _provider = "Local";
|
|
private bool _testing;
|
|
private StorageTestResult? _testResult;
|
|
|
|
private string GetStorageTestStatus()
|
|
{
|
|
if (_testResult?.Healthy is true) return "Opérationnel";
|
|
if (_testResult?.Configured is false) return "Non configuré";
|
|
return "Injoignable";
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
_settings = await Api.GetSettingsAsync();
|
|
}
|
|
catch
|
|
{
|
|
// API indisponible (ex : test) — on reste sur les défauts.
|
|
_settings = [];
|
|
}
|
|
_provider = GetValue("storage.provider") ?? "Local";
|
|
}
|
|
|
|
private string? GetValue(string key)
|
|
=> _settings.FirstOrDefault(s => s.Key == key)?.Value;
|
|
|
|
private async Task SaveProviderAsync(string provider)
|
|
{
|
|
_provider = provider;
|
|
await SaveValueAsync("storage.provider", provider);
|
|
}
|
|
|
|
private Task OnLocalPathChanged(string v) => SaveValueAsync("storage.local.path", v);
|
|
private Task OnEndpointChanged(string v) => SaveValueAsync("storage.s3.endpoint", v);
|
|
private Task OnBucketChanged(string v) => SaveValueAsync("storage.s3.bucket", v);
|
|
private Task OnAccessKeyChanged(string v) => SaveValueAsync("storage.s3.accessKey", v);
|
|
private Task OnSecretKeyChanged(string v) => SaveValueAsync("storage.s3.secretKey", v);
|
|
private Task OnRegionChanged(string v) => SaveValueAsync("storage.s3.region", v);
|
|
|
|
private async Task SaveValueAsync(string key, string? value)
|
|
{
|
|
value ??= string.Empty;
|
|
var existing = _settings.FirstOrDefault(s => s.Key == key);
|
|
try
|
|
{
|
|
if (existing is null)
|
|
{
|
|
await Api.CreateSettingAsync(new CreateAppSettingRequest(
|
|
Key: key, Value: value, Category: "storage",
|
|
Description: key.StartsWith("storage.s3.secretKey", StringComparison.Ordinal)
|
|
? "Clé secrète S3" : key,
|
|
ValueType: "string", AllowedValues: null, AgentScoped: false));
|
|
}
|
|
else
|
|
{
|
|
await Api.UpdateSettingAsync(key, new UpdateAppSettingRequest(
|
|
Value: value, Description: existing.Description ?? key,
|
|
Category: "storage", ValueType: "string", AllowedValues: null, AgentScoped: null));
|
|
}
|
|
// Les records sont immuables : recharger plutôt que muter.
|
|
_settings = await Api.GetSettingsAsync();
|
|
Snackbar.Add($"Paramètre {key} mis à jour", Severity.Success);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Échec de la mise à jour : {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private async Task TestAsync()
|
|
{
|
|
_testing = true;
|
|
try
|
|
{
|
|
_testResult = await Api.TestStorageAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Test impossible : {ex.Message}", Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
_testing = false;
|
|
}
|
|
}
|
|
}
|