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