mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-02-18 23:41:48 +01:00
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
This commit is contained in:
@@ -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...),
|
||||
|
||||
Reference in New Issue
Block a user