diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go index 500671d31..f428672e1 100644 --- a/cmd/podman/containers/stats.go +++ b/cmd/podman/containers/stats.go @@ -185,44 +185,12 @@ type containerStats struct { define.ContainerStats } -func (s *containerStats) ID() string { - return s.ContainerID[0:12] -} - -func (s *containerStats) CPUPerc() string { - return floatToPercentString(s.CPU) -} - -func (s *containerStats) AVGCPU() string { - return floatToPercentString(s.AvgCPU) -} - -func (s *containerStats) Up() string { - return (s.UpTime.String()) -} - -func (s *containerStats) MemPerc() string { - return floatToPercentString(s.ContainerStats.MemPerc) -} - -func (s *containerStats) NetIO() string { - return combineHumanValues(s.NetInput, s.NetOutput) -} - -func (s *containerStats) BlockIO() string { - return combineHumanValues(s.BlockInput, s.BlockOutput) -} - -func (s *containerStats) PIDS() string { - if s.PIDs == 0 { +func pidstring(pids uint64) string { + if pids == 0 { // If things go bazinga, return a safe value return "--" } - return fmt.Sprintf("%d", s.PIDs) -} - -func (s *containerStats) MemUsage() string { - return combineHumanValues(s.ContainerStats.MemUsage, s.ContainerStats.MemLimit) + return fmt.Sprintf("%d", pids) } func (s *containerStats) MemUsageBytes() string { @@ -268,16 +236,16 @@ func outputJSON(stats []containerStats) error { jstats := make([]jstat, 0, len(stats)) for _, j := range stats { jstats = append(jstats, jstat{ - Id: j.ID(), + Id: j.ContainerID[0:12], Name: j.Name, - CPUTime: j.Up(), - CpuPercent: j.CPUPerc(), - AverageCPU: j.AVGCPU(), - MemUsage: j.MemUsage(), - MemPerc: j.MemPerc(), - NetIO: j.NetIO(), - BlockIO: j.BlockIO(), - Pids: j.PIDS(), + CPUTime: j.UpTime.String(), + CpuPercent: floatToPercentString(j.CPU), + AverageCPU: floatToPercentString(j.AvgCPU), + MemUsage: combineHumanValues(j.ContainerStats.MemUsage, j.ContainerStats.MemLimit), + MemPerc: floatToPercentString(j.ContainerStats.MemPerc), + NetIO: combineHumanValues(j.NetInput, j.NetOutput), + BlockIO: combineHumanValues(j.BlockInput, j.BlockOutput), + Pids: pidstring(j.PIDs), }) } b, err := json.MarshalIndent(jstats, "", " ")