summaryrefslogtreecommitdiff
path: root/cmd/podman/stats.go
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-06-29 17:01:03 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-07 19:52:51 +0000
commit32dd5206064f11edd2f4d103a2bf2c0131b3f179 (patch)
treee58fdbb76ce8f3aceb11da13e8d41130658f5f4b /cmd/podman/stats.go
parentca6ffbccc2b47ffe74bb74ebae5a61504203966c (diff)
downloadpodman-32dd5206064f11edd2f4d103a2bf2c0131b3f179.tar.gz
podman-32dd5206064f11edd2f4d103a2bf2c0131b3f179.tar.bz2
podman-32dd5206064f11edd2f4d103a2bf2c0131b3f179.zip
Podman stats with no containers listed is the same as podman stats --all
Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1031 Approved by: rhatdan
Diffstat (limited to 'cmd/podman/stats.go')
-rw-r--r--cmd/podman/stats.go28
1 files changed, 24 insertions, 4 deletions
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: "",
+ }
+}