summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_stats.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pod_stats.go')
-rw-r--r--cmd/podman/pod_stats.go46
1 files changed, 7 insertions, 39 deletions
diff --git a/cmd/podman/pod_stats.go b/cmd/podman/pod_stats.go
index e0e5ca24e..46cacc026 100644
--- a/cmd/podman/pod_stats.go
+++ b/cmd/podman/pod_stats.go
@@ -13,6 +13,7 @@ import (
"github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -73,16 +74,13 @@ func podStatsCmd(c *cliconfig.PodStatsValues) 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 := adapter.GetRuntime(getContext(), &c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
- defer runtime.Shutdown(false)
+ defer runtime.DeferredShutdown(false)
times := -1
if c.NoStream {
@@ -93,24 +91,6 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
if err != nil {
return errors.Wrapf(err, "unable to get a list of pods")
}
- // First we need to get an initial pass of pod/ctr stats (these are not printed)
- var podStats []*adapter.PodContainerStats
- for _, p := range pods {
- cons, err := p.AllContainersByID()
- if err != nil {
- return err
- }
- emptyStats := make(map[string]*libpod.ContainerStats)
- // Iterate the pods container ids and make blank stats for them
- for _, c := range cons {
- emptyStats[c] = &libpod.ContainerStats{}
- }
- ps := adapter.PodContainerStats{
- Pod: p,
- ContainerStats: emptyStats,
- }
- podStats = append(podStats, &ps)
- }
// Create empty container stat results for our first pass
var previousPodStats []*adapter.PodContainerStats
@@ -153,7 +133,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
for _, p := range pods {
prevStat := getPreviousPodContainerStats(p.ID(), previousPodStats)
newPodStats, err := p.GetPodStats(prevStat)
- if errors.Cause(err) == libpod.ErrNoSuchPod {
+ if errors.Cause(err) == define.ErrNoSuchPod {
continue
}
if err != nil {
@@ -172,7 +152,9 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
tm.Flush()
}
if strings.ToLower(format) == formats.JSONString {
- outputJson(newStats)
+ if err := outputJson(newStats); err != nil {
+ return err
+ }
} else {
results := podContainerStatsToPodStatOut(newStats)
@@ -270,7 +252,7 @@ func printPSFormat(format string, stats []*podStatOut, headerNames map[string]st
func outputToStdOut(stats []*podStatOut) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
- outFormat := ("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n")
+ outFormat := "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n"
fmt.Fprintf(w, outFormat, "POD", "CID", "NAME", "CPU %", "MEM USAGE/ LIMIT", "MEM %", "NET IO", "BLOCK IO", "PIDS")
for _, i := range stats {
if len(stats) == 0 {
@@ -299,17 +281,3 @@ func outputJson(stats []*adapter.PodContainerStats) error {
fmt.Println(string(b))
return nil
}
-
-func getPodsByList(podList []string, r *libpod.Runtime) ([]*libpod.Pod, error) {
- var (
- pods []*libpod.Pod
- )
- for _, p := range podList {
- pod, err := r.LookupPod(p)
- if err != nil {
- return nil, err
- }
- pods = append(pods, pod)
- }
- return pods, nil
-}