mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
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
This commit is contained in:

committed by
Atomic Bot

parent
ca6ffbccc2
commit
32dd520606
@ -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: "",
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user