aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-09-10 10:53:47 -0400
committerGitHub <noreply@github.com>2021-09-10 10:53:47 -0400
commit0b6c56b80d7642e33f89b3f24cde53c7817e64d9 (patch)
tree41d6c41f0373883c284a087974bcda4355d11a83 /libpod
parentcf4a7b8d37c48bc9ccf8e5a2fdc9b005113fd847 (diff)
parent50688da29b4a37006d0a7fafc25aca1a6447c7d9 (diff)
downloadpodman-0b6c56b80d7642e33f89b3f24cde53c7817e64d9.tar.gz
podman-0b6c56b80d7642e33f89b3f24cde53c7817e64d9.tar.bz2
podman-0b6c56b80d7642e33f89b3f24cde53c7817e64d9.zip
Merge pull request #11506 from giuseppe/fix-stats-restart-container
stats: detect container restart and allow paused containers
Diffstat (limited to 'libpod')
-rw-r--r--libpod/stats.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/libpod/stats.go b/libpod/stats.go
index 6f0360ef1..975152535 100644
--- a/libpod/stats.go
+++ b/libpod/stats.go
@@ -30,7 +30,7 @@ func (c *Container) GetContainerStats(previousStats *define.ContainerStats) (*de
}
}
- if c.state.State != define.ContainerStateRunning {
+ if c.state.State != define.ContainerStateRunning && c.state.State != define.ContainerStatePaused {
return stats, define.ErrCtrStateInvalid
}
@@ -54,6 +54,12 @@ func (c *Container) GetContainerStats(previousStats *define.ContainerStats) (*de
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
now := uint64(time.Now().UnixNano())
stats.Duration = cgroupStats.CPU.Usage.Total
@@ -65,7 +71,7 @@ func (c *Container) GetContainerStats(previousStats *define.ContainerStats) (*de
stats.MemLimit = getMemLimit(cgroupStats.Memory.Usage.Limit)
stats.MemPerc = (float64(stats.MemUsage) / float64(stats.MemLimit)) * 100
stats.PIDs = 0
- if conState == define.ContainerStateRunning {
+ if conState == define.ContainerStateRunning || conState == define.ContainerStatePaused {
stats.PIDs = cgroupStats.Pids.Current
}
stats.BlockInput, stats.BlockOutput = calculateBlockIO(cgroupStats)