mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00:00
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
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user