From 32dd5206064f11edd2f4d103a2bf2c0131b3f179 Mon Sep 17 00:00:00 2001 From: haircommander Date: Fri, 29 Jun 2018 17:01:03 -0400 Subject: Podman stats with no containers listed is the same as podman stats --all Signed-off-by: haircommander Closes: #1031 Approved by: rhatdan --- cmd/podman/stats.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/stats.go b/cmd/podman/stats.go index 06e948d8c..d1015801f 100644 --- a/cmd/podman/stats.go +++ b/cmd/podman/stats.go @@ -77,6 +77,9 @@ func statsCmd(c *cli.Context) error { if ctr > 1 { return errors.Errorf("--all, --latest and containers cannot be used together") + } else if ctr == 0 { + // If user didn't specify, imply --all + all = true } runtime, err := libpodruntime.GetRuntime(c) @@ -169,13 +172,17 @@ func outputStats(stats []*libpod.ContainerStats, format string) error { for _, s := range stats { outputStats = append(outputStats, getStatsOutputParams(s)) } - if len(outputStats) == 0 { - return nil - } if strings.ToLower(format) == formats.JSONString { out = formats.JSONStructArray{Output: statsToGeneric(outputStats, []statsOutputParams{})} } else { - out = formats.StdoutTemplateArray{Output: statsToGeneric(outputStats, []statsOutputParams{}), Template: format, Fields: outputStats[0].headerMap()} + var mapOfHeaders map[string]string + if len(outputStats) == 0 { + params := getStatsOutputParamsEmpty() + mapOfHeaders = params.headerMap() + } else { + mapOfHeaders = outputStats[0].headerMap() + } + out = formats.StdoutTemplateArray{Output: statsToGeneric(outputStats, []statsOutputParams{}), Template: format, Fields: mapOfHeaders} } return formats.Writer(out).Out() } @@ -260,3 +267,16 @@ func getStatsOutputParams(stats *libpod.ContainerStats) statsOutputParams { PIDS: pidsToString(stats.PIDs), } } + +func getStatsOutputParamsEmpty() statsOutputParams { + return statsOutputParams{ + Name: "", + ID: "", + CPUPerc: "", + MemUsage: "", + MemPerc: "", + NetIO: "", + BlockIO: "", + PIDS: "", + } +} -- cgit v1.2.3-54-g00ecf