diff options
Diffstat (limited to 'cmd/podman/stats.go')
-rw-r--r-- | cmd/podman/stats.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/cmd/podman/stats.go b/cmd/podman/stats.go index c2b2a688c..3accae1b6 100644 --- a/cmd/podman/stats.go +++ b/cmd/podman/stats.go @@ -12,6 +12,7 @@ import ( "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/libpod" + "github.com/containers/libpod/libpod/define" "github.com/docker/go-units" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -92,7 +93,7 @@ func statsCmd(c *cliconfig.StatsValues) error { if err != nil { return errors.Wrapf(err, "could not get runtime") } - defer runtime.Shutdown(false) + defer runtime.DeferredShutdown(false) times := -1 if c.NoStream { @@ -100,9 +101,8 @@ func statsCmd(c *cliconfig.StatsValues) error { } var ctrs []*libpod.Container - var containerFunc func() ([]*libpod.Container, error) - containerFunc = runtime.GetRunningContainers + containerFunc := runtime.GetRunningContainers if len(c.InputArgs) > 0 { containerFunc = func() ([]*libpod.Container, error) { return runtime.GetContainersByList(c.InputArgs) } } else if latest { @@ -127,7 +127,7 @@ func statsCmd(c *cliconfig.StatsValues) error { initialStats, err := ctr.GetContainerStats(&libpod.ContainerStats{}) if err != nil { // when doing "all", dont worry about containers that are not running - if c.All && errors.Cause(err) == libpod.ErrCtrRemoved || errors.Cause(err) == libpod.ErrNoSuchCtr || errors.Cause(err) == libpod.ErrCtrStateInvalid { + if c.All && errors.Cause(err) == define.ErrCtrRemoved || errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == define.ErrCtrStateInvalid { continue } return err @@ -148,7 +148,7 @@ func statsCmd(c *cliconfig.StatsValues) error { id := ctr.ID() if _, ok := containerStats[ctr.ID()]; !ok { initialStats, err := ctr.GetContainerStats(&libpod.ContainerStats{}) - if errors.Cause(err) == libpod.ErrCtrRemoved || errors.Cause(err) == libpod.ErrNoSuchCtr || errors.Cause(err) == libpod.ErrCtrStateInvalid { + if errors.Cause(err) == define.ErrCtrRemoved || errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == define.ErrCtrStateInvalid { // skip dealing with a container that is gone continue } @@ -158,7 +158,7 @@ func statsCmd(c *cliconfig.StatsValues) error { containerStats[id] = initialStats } stats, err := ctr.GetContainerStats(containerStats[id]) - if err != nil && errors.Cause(err) != libpod.ErrNoSuchCtr { + if err != nil && errors.Cause(err) != define.ErrNoSuchCtr { return err } // replace the previous measurement with the current one @@ -174,7 +174,9 @@ func statsCmd(c *cliconfig.StatsValues) error { tm.MoveCursor(1, 1) tm.Flush() } - outputStats(reportStats, format) + if err := outputStats(reportStats, format); err != nil { + return err + } time.Sleep(time.Second) } return nil @@ -198,7 +200,7 @@ func outputStats(stats []*libpod.ContainerStats, format string) error { } out = formats.StdoutTemplateArray{Output: statsToGeneric(outputStats, []statsOutputParams{}), Template: format, Fields: mapOfHeaders} } - return formats.Writer(out).Out() + return out.Out() } func genStatsFormat(format string) string { |