From 4ff9e58c23d449275414123745b1356d3a64f75c Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sat, 10 Jan 2026 18:41:41 +0000 Subject: [PATCH] fix(dockeragent): use fallback memory reading in Docker-on-LXC When Docker daemon runs inside an LXC container, it may report 0 for MemTotal because it can't read the cgroup memory limits correctly. This caused the UI to show "0B / 7GB" and trigger false alerts with overflow percentages (214748364799.6%). The fix checks if Docker's info.MemTotal is 0 and falls back to gopsutil's /proc/meminfo reading (snapshot.Memory.TotalBytes) which works correctly in LXC environments. Fixes #1075 --- internal/dockeragent/collect.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/dockeragent/collect.go b/internal/dockeragent/collect.go index d76054d67..0f306d04b 100644 --- a/internal/dockeragent/collect.go +++ b/internal/dockeragent/collect.go @@ -113,6 +113,13 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) { services, tasks, swarmInfo := a.collectSwarmData(ctx, info, containers) + // Use Docker's MemTotal, but fall back to gopsutil's reading if Docker returns 0. + // This can happen in Docker-in-LXC setups where Docker daemon can't read host memory. + totalMemory := info.MemTotal + if totalMemory <= 0 && snapshot.Memory.TotalBytes > 0 { + totalMemory = snapshot.Memory.TotalBytes + } + report := agentsdocker.Report{ Agent: agentsdocker.AgentInfo{ ID: agentID, @@ -131,7 +138,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) { Architecture: info.Architecture, DockerVersion: info.ServerVersion, TotalCPU: info.NCPU, - TotalMemoryBytes: info.MemTotal, + TotalMemoryBytes: totalMemory, UptimeSeconds: uptime, CPUUsagePercent: safeFloat(snapshot.CPUUsagePercent), LoadAverage: append([]float64(nil), snapshot.LoadAverage...),