diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2021-09-09 16:56:33 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2021-09-10 09:03:08 +0200 |
commit | 53dc99fa609b5a18458e27b99df546df9095b5d0 (patch) | |
tree | 41a6e3d56fef274a5b36f8a0612c4d9d0f59c2f5 | |
parent | 63f6656f8fa79d7f6e01379d7ba0aa4ab3c03b37 (diff) | |
download | podman-53dc99fa609b5a18458e27b99df546df9095b5d0.tar.gz podman-53dc99fa609b5a18458e27b99df546df9095b5d0.tar.bz2 podman-53dc99fa609b5a18458e27b99df546df9095b5d0.zip |
stats: allow to read stats for paused containers
paused containers still a cgroup we can use to grab the stats.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
-rw-r--r-- | libpod/stats.go | 4 | ||||
-rw-r--r-- | test/e2e/pause_test.go | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/libpod/stats.go b/libpod/stats.go index 6f0360ef1..2532b35c2 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 } @@ -65,7 +65,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) diff --git a/test/e2e/pause_test.go b/test/e2e/pause_test.go index ea7a96428..2e5e07de9 100644 --- a/test/e2e/pause_test.go +++ b/test/e2e/pause_test.go @@ -79,6 +79,11 @@ var _ = Describe("Podman pause", func() { Expect(result).To(ExitWithError()) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(createdState)) + + // check we can read stats for a paused container + result = podmanTest.Podman([]string{"stats", "--no-stream", cid}) + result.WaitWithDefaultTimeout() + Expect(result).To(ExitWithError()) }) It("podman pause a running container by id", func() { |