feat(agent): télémétrie inventaire matériel — CPU/mémoire/disque/GPU/OS/réseau (Fixes #82 #83 #84 #85) (#137)

## 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
This commit is contained in:
Arnaud Dartois authored and Arnaud Dartois committed 2026-08-20 14:13:06 +02:00
1 parent f7e6b0cec3
commit 4792b69e46
63 files changed
+8711 -563

No files matched your search

+124 -1
View File
@@ -19,7 +19,7 @@ public class Agent : Entity<Guid>, IAuditableEntity, ISoftDeletable
/// <summary>First 8 characters of the API key for identification.</summary>
public string? ApiKeyPrefix { get; private set; }
// Capabilities
// Capabilities (legacy)
public bool HasGpu { get; private set; }
public int CpuCores { get; private set; }
public long MemoryMb { get; private set; }
@@ -31,6 +31,47 @@ public class Agent : Entity<Guid>, IAuditableEntity, ISoftDeletable
public double? DiskUsagePercent { get; private set; }
public long? UptimeSeconds { get; private set; }
// ─── CPU inventory ────────────────────────────────────────────
public string? CpuVendor { get; private set; }
public string? CpuModel { get; private set; }
public string? CpuArchitecture { get; private set; }
public int? PhysicalCores { get; private set; }
public int? LogicalCores { get; private set; }
public int? ThreadsPerCore { get; private set; }
public double? CpuFrequencyMhz { get; private set; }
public string? CpuFlags { get; private set; }
public long? CpuCacheBytes { get; private set; }
// ─── Memory inventory ─────────────────────────────────────────
public long? MemTotalBytes { get; private set; }
public long? MemAvailableBytes { get; private set; }
public long? SwapTotalBytes { get; private set; }
public long? SwapFreeBytes { get; private set; }
// ─── Container limits ─────────────────────────────────────────
public long? ContainerCpuLimit { get; private set; }
public long? ContainerMemoryLimitBytes { get; private set; }
// ─── Disk inventory (JSON) ────────────────────────────────────
public string? DiskInventoryJson { get; private set; }
// ─── GPU inventory (JSON) ─────────────────────────────────────
public string? GpuInventoryJson { get; private set; }
// ─── Host info ────────────────────────────────────────────────
public string? OsName { get; private set; }
public string? KernelVersion { get; private set; }
public string? Arch { get; private set; }
public long? UptimeMachineSeconds { get; private set; }
// ─── Container info ───────────────────────────────────────────
public string? ContainerId { get; private set; }
public string? ContainerImage { get; private set; }
// ─── Network & Temperature (JSON) ─────────────────────────────
public string? NetworkInterfacesJson { get; private set; }
public string? TemperatureJson { get; private set; }
// Audit
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
@@ -106,4 +147,86 @@ public class Agent : Entity<Guid>, IAuditableEntity, ISoftDeletable
IsDeleted = true;
DeletedAt = DateTime.UtcNow;
}
// ─── Inventory update methods ─────────────────────────────────
public void UpdateCpuInventory(CpuInventoryData data)
{
CpuVendor = data.Vendor;
CpuModel = data.Model;
CpuArchitecture = data.Architecture;
PhysicalCores = data.PhysicalCores;
LogicalCores = data.LogicalCores;
ThreadsPerCore = data.ThreadsPerCore;
CpuFrequencyMhz = data.FrequencyMhz;
CpuFlags = data.Flags;
CpuCacheBytes = data.CacheBytes;
ContainerCpuLimit = data.ContainerCpuLimit;
}
public void UpdateMemoryDiskInventory(MemoryDiskInventoryData data)
{
MemTotalBytes = data.MemTotalBytes;
MemAvailableBytes = data.MemAvailableBytes;
SwapTotalBytes = data.SwapTotalBytes;
SwapFreeBytes = data.SwapFreeBytes;
ContainerMemoryLimitBytes = data.ContainerMemoryLimitBytes;
DiskInventoryJson = data.DiskInventoryJson;
}
public void UpdateGpuInventory(string? gpuInventoryJson)
{
GpuInventoryJson = gpuInventoryJson;
}
public void UpdateHostInventory(HostInventoryData data)
{
OsName = data.OsName;
KernelVersion = data.KernelVersion;
Arch = data.Arch;
UptimeMachineSeconds = data.UptimeMachineSeconds;
ContainerId = data.ContainerId;
ContainerImage = data.ContainerImage;
NetworkInterfacesJson = data.NetworkInterfacesJson;
TemperatureJson = data.TemperatureJson;
}
}
/// <summary>
/// Groups CPU inventory fields to keep the update method under the parameter limit.
/// </summary>
public sealed record CpuInventoryData(
string? Vendor,
string? Model,
string? Architecture,
int? PhysicalCores,
int? LogicalCores,
int? ThreadsPerCore,
double? FrequencyMhz,
string? Flags,
long? CacheBytes,
long? ContainerCpuLimit);
/// <summary>
/// Groups memory and disk inventory fields.
/// </summary>
public sealed record MemoryDiskInventoryData(
long? MemTotalBytes,
long? MemAvailableBytes,
long? SwapTotalBytes,
long? SwapFreeBytes,
long? ContainerMemoryLimitBytes,
string? DiskInventoryJson);
/// <summary>
/// Groups host/container/network/temperature inventory fields.
/// </summary>
public sealed record HostInventoryData(
string? OsName,
string? KernelVersion,
string? Arch,
long? UptimeMachineSeconds,
string? ContainerId,
string? ContainerImage,
string? NetworkInterfacesJson,
string? TemperatureJson);