From d389345153d61c8647deedb655900e8906110cd4 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 12 Jan 2026 21:14:26 +0000 Subject: [PATCH] fix(hosts): calculate Used memory from Total-Free for host agents in LXC The previous fix (4090d981) addressed memory reporting for Docker agents running in LXC containers, but the same issue also affects host agents. When gopsutil runs inside an LXC, it can read Total and Free memory from cgroup limits, but reports 0 for Used memory. Added the same Total - Free fallback calculation to the host agent processing path, which populates the Hosts tab. Fixes #1075 --- internal/monitoring/monitor.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index b09e667fa..327abd6cb 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -2362,6 +2362,16 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config. SwapTotal: report.Metrics.Memory.SwapTotal, SwapUsed: report.Metrics.Memory.SwapUsed, } + + // Fallback for LXC environments: gopsutil may read Total and Free correctly + // from cgroup limits but return 0 for Used. Calculate Used from Total - Free. + if memory.Used <= 0 && memory.Total > 0 && memory.Free > 0 { + memory.Used = memory.Total - memory.Free + if memory.Used < 0 { + memory.Used = 0 + } + } + if memory.Usage <= 0 && memory.Total > 0 { memory.Usage = safePercentage(float64(memory.Used), float64(memory.Total)) }