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:
parent
d93e17e898
commit
806cdd2d87
1 changed files with 2 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue