From 4090d98160f1032dd8eb731931c182fb9855db68 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 12 Jan 2026 14:04:38 +0000 Subject: [PATCH] fix(docker): calculate Used memory from Total-Free in Docker-in-LXC When running Docker inside an LXC container, gopsutil can read the Total memory (from cgroup limits) and Free memory correctly, but returns 0 for Used memory. This caused the display to show "0B / 7GB" even though memory was being used. Added a fallback that calculates Used = Total - Free when Used is 0 but Total and Free are valid. This completes the fallback chain for Docker-in-LXC memory reporting. Fixes #1075 --- internal/monitoring/monitor.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index fbd976449..b09e667fa 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -2040,6 +2040,20 @@ func (m *Monitor) ApplyDockerReport(report agentsdocker.Report, tokenRecord *con memory.Total = report.Host.TotalMemoryBytes } + // Additional fallback for Docker-in-LXC: gopsutil may read Total and Free + // correctly from cgroup limits but return 0 for Used. Calculate Used from + // Total - Free when this happens. This fixes the "0B / 7GB" display issue. + if memory.Used <= 0 && memory.Total > 0 && memory.Free > 0 { + memory.Used = memory.Total - memory.Free + if memory.Used < 0 { + memory.Used = 0 + } + // Recalculate usage percentage + if memory.Total > 0 { + memory.Usage = safePercentage(float64(memory.Used), float64(memory.Total)) + } + } + disks := make([]models.Disk, 0, len(report.Host.Disks)) for _, disk := range report.Host.Disks { disks = append(disks, models.Disk{