diff options
author | baude <bbaude@redhat.com> | 2018-08-08 15:16:01 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-08-17 07:55:36 +0000 |
commit | bf741b3ea30f9431775f03cca081758efcb780b1 (patch) | |
tree | 07e1b78dc585c2f4c70c04ef49b8c7cd92d59193 /libpod/runtime_pod.go | |
parent | 1b87fbc591bf13bc7ba55d5a70334237fe8620d7 (diff) | |
download | podman-bf741b3ea30f9431775f03cca081758efcb780b1.tar.gz podman-bf741b3ea30f9431775f03cca081758efcb780b1.tar.bz2 podman-bf741b3ea30f9431775f03cca081758efcb780b1.zip |
podman pod stats
add the ability to monitor container statistics in a pod.
Signed-off-by: baude <bbaude@redhat.com>
Closes: #1265
Approved by: rhatdan
Diffstat (limited to 'libpod/runtime_pod.go')
-rw-r--r-- | libpod/runtime_pod.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libpod/runtime_pod.go b/libpod/runtime_pod.go index f5a2b017b..280699b79 100644 --- a/libpod/runtime_pod.go +++ b/libpod/runtime_pod.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/containers/libpod/pkg/util" "github.com/pkg/errors" ) @@ -129,3 +130,36 @@ func (r *Runtime) GetLatestPod() (*Pod, error) { } return pods[lastCreatedIndex], nil } + +// GetRunningPods returns an array of running pods +func (r *Runtime) GetRunningPods() ([]*Pod, error) { + var ( + pods []string + runningPods []*Pod + ) + r.lock.RLock() + defer r.lock.RUnlock() + + if !r.valid { + return nil, ErrRuntimeStopped + } + containers, err := r.GetRunningContainers() + if err != nil { + return nil, err + } + // Assemble running pods + for _, c := range containers { + if !util.StringInSlice(c.PodID(), pods) { + pods = append(pods, c.PodID()) + pod, err := r.GetPod(c.PodID()) + if err != nil { + if errors.Cause(err) == ErrPodRemoved || errors.Cause(err) == ErrNoSuchPod { + continue + } + return nil, err + } + runningPods = append(runningPods, pod) + } + } + return runningPods, nil +} |