Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Make the Docker-in-LXC mock fixture survive the demo scenario layer
rcourtmana1ca8afa4c13
diff --git a/internal/mock/demo_scenarios.go b/internal/mock/demo_scenarios.goindex a4543af875..4abf5d6b56 100644--- a/internal/mock/demo_scenarios.go+++ b/internal/mock/demo_scenarios.go@@ -292,7 +292,7 @@ var demoProxmoxClusterProfiles = []demoProxmoxClusterProfile{const demoOfflineProxmoxNode = "pve22"-func applyDemoScenarioGraph(graph *FixtureGraph, now time.Time) {+func applyDemoScenarioGraph(graph *FixtureGraph, cfg MockConfig, now time.Time) {if graph == nil {return}@@ -302,6 +302,10 @@ func applyDemoScenarioGraph(graph *FixtureGraph, now time.Time) {vmProfiles := applyDemoWorkloadScenario(graph.State.VMs, demoVMProfiles, now)containerProfiles := applyDemoContainerScenario(graph.State.Containers, demoContainerProfiles, now)applyDemoDockerScenario(&graph.State, now)+ // Docker-in-LXC nested hosts bind to the guests' final (scenario-shaped)+ // names, instances, and states, so the fixture runs after the workload+ // and Docker scenarios and before connection health is synced.+ ensureMockDockerInLXCFixture(&graph.State, cfg)applyDemoKubernetesScenario(&graph.State, now)applyDemoHostScenario(&graph.State, now)applyDemoStorageScenario(&graph.State, now)@@ -571,9 +575,19 @@ func applyDemoDockerScenario(state *models.StateSnapshot, now time.Time) {// disconnected host with its containers shown as exited rather than running.const offlineDockerIndex = 2onlineOrdinal := 0+ nativeIndex := -1for i := range state.DockerHosts {host := &state.DockerHosts[i]- if i == offlineDockerIndex {+ if strings.HasPrefix(host.ID, mockProxmoxLXCDockerHostSourcePrefix) {+ // Docker-in-LXC hosts are identity-bound to their parent LXC+ // guest; ensureMockDockerInLXCFixture owns their naming, status,+ // and inventory. Handing them a fleet profile would sever the+ // guest linkage and fabricate native engine inventory the+ // production pct exec path never reports.+ continue+ }+ nativeIndex+++ if nativeIndex == offlineDockerIndex {host.Hostname = "field-office-edge-01"host.DisplayName = "Field Office Edge 01"host.Status = "offline"diff --git a/internal/mock/fixture_graph.go b/internal/mock/fixture_graph.goindex 0b968c37cd..fee6e1c4fe 100644--- a/internal/mock/fixture_graph.go+++ b/internal/mock/fixture_graph.go@@ -34,7 +34,7 @@ func buildFixtureGraph(cfg MockConfig, now time.Time) FixtureGraph {PlatformFixtures: defaultPlatformFixtures(),AvailabilityFixtures: defaultAvailabilityFixtures(now),}- applyDemoScenarioGraph(&graph, now)+ applyDemoScenarioGraph(&graph, cfg, now)syncMetricFixtureRegistriesFromGraph(graph)graph.UpdateMetrics(cfg, now)graph.AlertHistory = buildAlertHistory(graph.State.Nodes, graph.State.VMs, graph.State.Containers)@@ -61,12 +61,12 @@ func (g *FixtureGraph) UpdateMetrics(cfg MockConfig, now time.Time) {}setMockUpdateInterval(cfg.UpdateInterval)- applyDemoScenarioGraph(g, now)+ applyDemoScenarioGraph(g, cfg, now)syncMetricFixtureRegistriesFromGraph(*g)updateFixtureStateMetricsAt(&g.State, cfg, now)g.PlatformFixtures = rebasePlatformFixtures(g.PlatformFixtures, now)g.AvailabilityFixtures = rebaseAvailabilityFixtures(g.AvailabilityFixtures, now)- applyDemoScenarioGraph(g, now)+ applyDemoScenarioGraph(g, cfg, now)g.DiscoveryFixtures = buildDiscoveryFixtures(g.State, now)syncMetricFixtureRegistriesFromGraph(*g)}diff --git a/internal/mock/generator.go b/internal/mock/generator.goindex 405936295b..129609a180 100644--- a/internal/mock/generator.go+++ b/internal/mock/generator.go@@ -641,7 +641,9 @@ func buildFixtureState(config MockConfig) models.StateSnapshot {ensureFreshFilesystemFixture(&data)ensureConfigOnlyMountFixture(&data)- ensureMockDockerInLXCFixture(&data, config)+ // Docker-in-LXC nested hosts are added by ensureMockDockerInLXCFixture+ // from the demo scenario layer, after guests get their final names,+ // instances, and states.// Calculate statsdata.Stats.StartTime = time.Now()@@ -2706,15 +2708,42 @@ const mockProxmoxLXCDockerHostSourcePrefix = "proxmox-lxc-docker:"// and lets the Proxmox page match them back to their parent guest for the// row cue and drawer card, so without this fixture the whole surface has no// local reproduction.+//+// It runs AFTER the demo scenario layer (from applyDemoScenarioGraph), because+// the scenario renames guests, aliases cluster instances, and forces guest+// states; a nested host bound to pre-scenario coordinates would never match+// its parent again. The scenario reapplies on every metric tick, so this is+// idempotent: an existing nested host is re-synced from its guest instead of+// duplicated, and one whose guest stopped running goes offline the way a real+// probe target would.func ensureMockDockerInLXCFixture(data *models.StateSnapshot, config MockConfig) {- if data == nil || config.DockerHostCount <= 0 {+ if data == nil {+ return+ }+ if data.ConnectionHealth == nil {+ data.ConnectionHealth = make(map[string]bool)+ }++ existing := make(map[string]*models.DockerHost)+ for i := range data.DockerHosts {+ host := &data.DockerHosts[i]+ if strings.HasPrefix(host.ID, mockProxmoxLXCDockerHostSourcePrefix) {+ existing[host.ID] = host+ }+ }++ if config.DockerHostCount <= 0 {+ for _, host := range existing {+ host.Status = "offline"+ }return}+ now := time.Now()// One single-container guest and one busier guest, so the row cue// renders both its singular and plural counts.nestedCounts := []int{1, 4}- now := time.Now()+ selected := make(map[string]bool, len(nestedCounts))nested := 0for i := range data.Containers {if nested >= len(nestedCounts) {@@ -2724,14 +2753,25 @@ func ensureMockDockerInLXCFixture(data *models.StateSnapshot, config MockConfig)if ct.Status != "running" || ct.IsOCI {continue}+ nestedIdx := nested+ nested++ct.HasDocker = true- ct.DockerCheckedAt = now+ if ct.DockerCheckedAt.IsZero() {+ ct.DockerCheckedAt = now+ }sourceID := fmt.Sprintf("%s%s:%s:%d", mockProxmoxLXCDockerHostSourcePrefix, ct.Instance, ct.Node, ct.VMID)+ selected[sourceID] = true+ if host, ok := existing[sourceID]; ok {+ syncMockDockerInLXCHostFromGuest(host, *ct, now)+ data.ConnectionHealth[dockerConnectionPrefix+host.ID] = true+ continue+ }+containers := generateDockerContainers(ct.Name, i, config, false)- if len(containers) > nestedCounts[nested] {- containers = containers[:nestedCounts[nested]]+ if len(containers) > nestedCounts[nestedIdx] {+ containers = containers[:nestedCounts[nestedIdx]]}version := dockerVersions[rand.Intn(len(dockerVersions))]@@ -2743,49 +2783,86 @@ func ensureMockDockerInLXCFixture(data *models.StateSnapshot, config MockConfig)}}- // Host info mirrors what parseProxmoxGuestDockerInventory plus- // enrichGuestDockerReportFromContainer report for a real guest: the- // guest's own sizing and usage, one rootfs disk, no machine ID, no- // agent version, no network interfaces.host := models.DockerHost{- ID: sourceID,- AgentID: sourceID,- Hostname: ct.Name,- DisplayName: ct.Name,- OS: "linux",- KernelVersion: kernelVersion,- Architecture: "x86_64",- Runtime: "docker",- RuntimeVersion: version,- DockerVersion: version,- CPUs: ct.CPUs,- TotalMemoryBytes: ct.Memory.Total,- UptimeSeconds: ct.Uptime,- CPUUsage: clampFloat(ct.CPU*100, 0, 100),- Memory: models.Memory{- Total: ct.Memory.Total,- Used: ct.Memory.Used,- Free: ct.Memory.Free,- Usage: ct.Memory.Usage,- },- Disks: []models.Disk{{- Total: ct.Disk.Total,- Used: ct.Disk.Used,- Free: ct.Disk.Free,- Usage: ct.Disk.Usage,- Mountpoint: "/",- Type: "rootfs",- }},- Status: "online",- LastSeen: now,- IntervalSeconds: 30,- Containers: containers,+ ID: sourceID,+ OS: "linux",+ KernelVersion: kernelVersion,+ Architecture: "x86_64",+ Runtime: "docker",+ RuntimeVersion: version,+ DockerVersion: version,+ Containers: containers,}+ syncMockDockerInLXCHostFromGuest(&host, *ct, now)data.DockerHosts = append(data.DockerHosts, host)data.ConnectionHealth[dockerConnectionPrefix+host.ID] = true- nested++}++ // A nested host whose guest is no longer among the running targets stops+ // reporting, exactly like a real probe target whose LXC was stopped.+ for id, host := range existing {+ if !selected[id] {+ host.Status = "offline"+ data.ConnectionHealth[dockerConnectionPrefix+id] = false+ }+ }+}++// syncMockDockerInLXCHostFromGuest keeps a nested Docker host mirroring its+// parent LXC guest, matching what parseProxmoxGuestDockerInventory plus+// enrichGuestDockerReportFromContainer report for a real guest: the guest's+// own naming, sizing, and usage, one rootfs disk, and none of the native+// agent surfaces (engine inventory, Swarm, host I/O rates, temperature,+// machine ID, agent version, network interfaces). Clearing those every pass+// also repairs any enrichment a demo cycle may have applied before the+// scenario learned to skip nested hosts.+func syncMockDockerInLXCHostFromGuest(host *models.DockerHost, guest models.Container, now time.Time) {+ if host == nil {+ return+ }+ host.AgentID = host.ID+ host.Hostname = guest.Name+ host.DisplayName = guest.Name+ host.Status = "online"+ host.CPUs = guest.CPUs+ host.TotalMemoryBytes = guest.Memory.Total+ host.UptimeSeconds = guest.Uptime+ host.CPUUsage = clampFloat(guest.CPU*100, 0, 100)+ host.Memory = models.Memory{+ Total: guest.Memory.Total,+ Used: guest.Memory.Used,+ Free: guest.Memory.Free,+ Usage: guest.Memory.Usage,+ }+ host.Disks = []models.Disk{{+ Total: guest.Disk.Total,+ Used: guest.Disk.Used,+ Free: guest.Disk.Free,+ Usage: guest.Disk.Usage,+ Mountpoint: "/",+ Type: "rootfs",+ }}+ host.LastSeen = now+ host.IntervalSeconds = 30+ host.MachineID = ""+ host.AgentVersion = ""+ host.NetworkInterfaces = nil+ host.Images = nil+ host.Volumes = nil+ host.Networks = nil+ host.StorageUsage = nil+ host.Services = nil+ host.Tasks = nil+ host.Secrets = nil+ host.Configs = nil+ host.Nodes = nil+ host.Swarm = nil+ host.Temperature = nil+ host.NetInRate = 0+ host.NetOutRate = 0+ host.DiskReadRate = 0+ host.DiskWriteRate = 0}func ensureMockDockerNativeInventory(host *models.DockerHost, hostIndex int, now time.Time) {diff --git a/internal/mock/generator_test.go b/internal/mock/generator_test.goindex 7b6b51a8fb..26ee741bb7 100644--- a/internal/mock/generator_test.go+++ b/internal/mock/generator_test.go@@ -906,11 +906,8 @@ func TestEnsureConfigOnlyMountFixtureSeedsUnknownUsageMount(t *testing.T) {}}-func TestBuildFixtureStateIncludesDockerInLXCFixture(t *testing.T) {- cfg := DefaultConfig- cfg.StoppedPercent = 0 // keep every LXC running so the fixture always binds-- data := buildFixtureState(cfg)+func assertMockDockerInLXCFixture(t *testing.T, data *models.StateSnapshot) []models.DockerHost {+ t.Helper()var nested []models.DockerHostfor _, host := range data.DockerHosts {@@ -946,6 +943,9 @@ func TestBuildFixtureStateIncludesDockerInLXCFixture(t *testing.T) {if host.Hostname != guest.Name {t.Fatalf("nested docker host hostname %q should be the guest name %q", host.Hostname, guest.Name)}+ if host.Status != "online" {+ t.Fatalf("nested docker host %s bound to a running guest must be online, got %q", host.ID, host.Status)+ }if len(host.Containers) == 0 {t.Fatalf("nested docker host %s has no containers", host.ID)}@@ -963,16 +963,41 @@ func TestBuildFixtureStateIncludesDockerInLXCFixture(t *testing.T) {if !containerCounts[1] {t.Fatalf("expected one single-container nested host so the row cue renders its singular form, got counts %v", containerCounts)}+ return nested+}++func TestFixtureGraphIncludesDockerInLXCFixture(t *testing.T) {+ cfg := DefaultConfig+ now := time.Now()++ graph := buildFixtureGraph(cfg, now)+ first := assertMockDockerInLXCFixture(t, &graph.State)++ // The demo scenario layer reapplies on every metric tick; the fixture+ // must stay idempotent and the scenario's Docker fleet profiles must+ // keep their hands off the nested hosts.+ graph.UpdateMetrics(cfg, now.Add(time.Minute))+ second := assertMockDockerInLXCFixture(t, &graph.State)+ firstIDs := map[string]bool{}+ for _, host := range first {+ firstIDs[host.ID] = true+ }+ for _, host := range second {+ if !firstIDs[host.ID] {+ t.Fatalf("nested docker host identity changed across ticks: %s not in first pass", host.ID)+ }+ }// Disabling Docker in the mock estate disables the nested fixture too.- cfg.DockerHostCount = 0- dataNoDocker := buildFixtureState(cfg)- for _, host := range dataNoDocker.DockerHosts {+ cfgNoDocker := DefaultConfig+ cfgNoDocker.DockerHostCount = 0+ graphNoDocker := buildFixtureGraph(cfgNoDocker, now)+ for _, host := range graphNoDocker.State.DockerHosts {if strings.HasPrefix(host.ID, mockProxmoxLXCDockerHostSourcePrefix) {t.Fatalf("nested docker host %s generated despite DockerHostCount=0", host.ID)}}- for _, ct := range dataNoDocker.Containers {+ for _, ct := range graphNoDocker.State.Containers {if ct.HasDocker {t.Fatalf("LXC %s marked HasDocker despite DockerHostCount=0", ct.ID)}