summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-08-16 18:26:24 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-23 15:01:17 +0000
commit88df4ea0f97f2892a6fd588bd3abfad1db634629 (patch)
tree9ecea1234ccf25488095c9b2150ad625c21a3716 /libpod
parent6c253d00554d5f5c17cc7bbb76e9658f277ab129 (diff)
downloadpodman-88df4ea0f97f2892a6fd588bd3abfad1db634629.tar.gz
podman-88df4ea0f97f2892a6fd588bd3abfad1db634629.tar.bz2
podman-88df4ea0f97f2892a6fd588bd3abfad1db634629.zip
Add podman pod top
Using the vendored changes from psgo, incorporate JoinNamespaceAndProcessInfoByPids to get process information for each pid namespace of running containers in the pod. Also added a man page, and tests. Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1298 Approved by: mheon
Diffstat (limited to 'libpod')
-rw-r--r--libpod/pod_top_linux.go55
-rw-r--r--libpod/pod_top_unsupported.go8
2 files changed, 63 insertions, 0 deletions
diff --git a/libpod/pod_top_linux.go b/libpod/pod_top_linux.go
new file mode 100644
index 000000000..f49e28c9d
--- /dev/null
+++ b/libpod/pod_top_linux.go
@@ -0,0 +1,55 @@
+// +build linux
+
+package libpod
+
+import (
+ "strconv"
+ "strings"
+
+ "github.com/containers/psgo"
+)
+
+// GetPodPidInformation returns process-related data of all processes in
+// the pod. The output data can be controlled via the `descriptors`
+// argument which expects format descriptors and supports all AIXformat
+// descriptors of ps (1) plus some additional ones to for instance inspect the
+// set of effective capabilities. Eeach element in the returned string slice
+// is a tab-separated string.
+//
+// For more details, please refer to github.com/containers/psgo.
+func (p *Pod) GetPodPidInformation(descriptors []string) ([]string, error) {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+
+ pids := make([]string, 0)
+ ctrsInPod, err := p.allContainers()
+ if err != nil {
+ return nil, err
+ }
+ for _, c := range ctrsInPod {
+ c.lock.Lock()
+
+ if err := c.syncContainer(); err != nil {
+ c.lock.Unlock()
+ return nil, err
+ }
+ if c.state.State == ContainerStateRunning {
+ pid := strconv.Itoa(c.state.PID)
+ pids = append(pids, pid)
+ }
+ c.lock.Unlock()
+ }
+ // TODO: psgo returns a [][]string to give users the ability to apply
+ // filters on the data. We need to change the API here and the
+ // varlink API to return a [][]string if we want to make use of
+ // filtering.
+ output, err := psgo.JoinNamespaceAndProcessInfoByPids(pids, descriptors)
+ if err != nil {
+ return nil, err
+ }
+ res := []string{}
+ for _, out := range output {
+ res = append(res, strings.Join(out, "\t"))
+ }
+ return res, nil
+}
diff --git a/libpod/pod_top_unsupported.go b/libpod/pod_top_unsupported.go
new file mode 100644
index 000000000..d44470523
--- /dev/null
+++ b/libpod/pod_top_unsupported.go
@@ -0,0 +1,8 @@
+// +build !linux
+
+package libpod
+
+// GetPodPidInformation is exclusive to linux
+func (p *Pod) GetPodPidInformation(descriptors []string) ([]string, error) {
+ return nil, ErrNotImplemented
+}