From 806cdd2d87f7ebbd934928de7e6d5eba8561cc9b Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 28 Nov 2025 15:07:49 +0000 Subject: [PATCH] Fix Docker CPU calculation on systemUsage counter reset When systemUsage counter goes backward (common in unprivileged LXC containers), the previous code used the absolute value as systemDelta. This created an artificially small denominator, inflating CPU to ~100%. Now leaves systemDelta as 0 on counter reset, falling through to the time-based calculation which produces accurate results. Related to #770 --- internal/dockeragent/agent.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/dockeragent/agent.go b/internal/dockeragent/agent.go index 7c2f3a9..942e4a0 100644 --- a/internal/dockeragent/agent.go +++ b/internal/dockeragent/agent.go @@ -1377,9 +1377,9 @@ func (a *Agent) calculateContainerCPUPercent(id string, stats containertypes.Sta var systemDelta float64 if current.systemUsage >= prev.systemUsage { systemDelta = float64(current.systemUsage - prev.systemUsage) - } else if current.systemUsage > 0 { - systemDelta = float64(current.systemUsage) } + // If systemUsage went backward (counter reset), leave systemDelta as 0 + // to fall through to time-based calculation below if systemDelta > 0 { cpuPercent := safeFloat((totalDelta / systemDelta) * float64(onlineCPUs) * 100.0)