From 70306466d08c0e52a5a70c6d8eb8b021f95d22de Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Thu, 18 Jan 2018 15:54:16 -0500 Subject: Cleanup of podman stats Fix errors when containers are not running. --all, --latest, containers can not be used at same time. Should match the output of docker stats, 0 values replaced by "--" Should return stats right away if container is not running. Signed-off-by: Daniel J Walsh Closes: #244 Approved by: TomSweeneyRedHat --- libpod/stats.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/stats.go b/libpod/stats.go index 86da0679e..e87654277 100644 --- a/libpod/stats.go +++ b/libpod/stats.go @@ -29,11 +29,16 @@ type ContainerStats struct { // GetContainerStats gets the running stats for a given container func (c *Container) GetContainerStats(previousStats *ContainerStats) (*ContainerStats, error) { stats := new(ContainerStats) + stats.ContainerID = c.ID() c.lock.Lock() defer c.lock.Unlock() if err := c.syncContainer(); err != nil { return stats, errors.Wrapf(err, "error updating container %s state", c.ID()) } + if c.state.State != ContainerStateRunning { + return stats, nil + } + cgroup, err := cgroups.Load(cgroups.V1, c.CGroupPath()) if err != nil { return stats, errors.Wrapf(err, "unable to load cgroup at %+v", c.CGroupPath()) @@ -50,7 +55,6 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container previousCPU := previousStats.CPUNano previousSystem := previousStats.SystemNano - stats.ContainerID = c.ID() stats.CPU = calculateCPUPercent(cgroupStats, previousCPU, previousSystem) stats.MemUsage = cgroupStats.Memory.Usage.Usage stats.MemLimit = getMemLimit(cgroupStats.Memory.Usage.Limit) -- cgit v1.2.3-54-g00ecf