mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +08:00
stats: detect containers restart
if the current cpu usage time is lower than what previously recorded, then it means the container was restarted and now it runs in a new cgroup. When this happens, reset the prevStats. Closes: https://github.com/containers/podman/issues/11469 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -54,6 +54,12 @@ func (c *Container) GetContainerStats(previousStats *define.ContainerStats) (*de
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the current total usage in the cgroup is less than what was previously
|
||||||
|
// recorded then it means the container was restarted and runs in a new cgroup
|
||||||
|
if previousStats.Duration > cgroupStats.CPU.Usage.Total {
|
||||||
|
previousStats = &define.ContainerStats{}
|
||||||
|
}
|
||||||
|
|
||||||
previousCPU := previousStats.CPUNano
|
previousCPU := previousStats.CPUNano
|
||||||
now := uint64(time.Now().UnixNano())
|
now := uint64(time.Now().UnixNano())
|
||||||
stats.Duration = cgroupStats.CPU.Usage.Total
|
stats.Duration = cgroupStats.CPU.Usage.Total
|
||||||
|
Reference in New Issue
Block a user