mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00: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)
|
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{
|
report := agentsdocker.Report{
|
||||||
Agent: agentsdocker.AgentInfo{
|
Agent: agentsdocker.AgentInfo{
|
||||||
ID: agentID,
|
ID: agentID,
|
||||||
@@ -131,7 +138,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) {
|
|||||||
Architecture: info.Architecture,
|
Architecture: info.Architecture,
|
||||||
DockerVersion: info.ServerVersion,
|
DockerVersion: info.ServerVersion,
|
||||||
TotalCPU: info.NCPU,
|
TotalCPU: info.NCPU,
|
||||||
TotalMemoryBytes: info.MemTotal,
|
TotalMemoryBytes: totalMemory,
|
||||||
UptimeSeconds: uptime,
|
UptimeSeconds: uptime,
|
||||||
CPUUsagePercent: safeFloat(snapshot.CPUUsagePercent),
|
CPUUsagePercent: safeFloat(snapshot.CPUUsagePercent),
|
||||||
LoadAverage: append([]float64(nil), snapshot.LoadAverage...),
|
LoadAverage: append([]float64(nil), snapshot.LoadAverage...),
|
||||||
|
|||||||
Reference in New Issue
Block a user