summaryrefslogtreecommitdiff
path: root/pkg/varlinkapi/pods.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-03-06 12:24:13 -0800
committerGitHub <noreply@github.com>2019-03-06 12:24:13 -0800
commit02e2342d20a01c89236b4c2f2867e6acd8eda923 (patch)
tree8c0ecfb6f8666d80328a564106c53214f66e3e97 /pkg/varlinkapi/pods.go
parentf50715ed25fd1bc58dad39982a2a5b5837dcd8ef (diff)
parent788f818cc53fbd68267c2c6ab5de8655938414cb (diff)
downloadpodman-02e2342d20a01c89236b4c2f2867e6acd8eda923.tar.gz
podman-02e2342d20a01c89236b4c2f2867e6acd8eda923.tar.bz2
podman-02e2342d20a01c89236b4c2f2867e6acd8eda923.zip
Merge pull request #2442 from baude/remotepodtop
podman-remote pod top|stats
Diffstat (limited to 'pkg/varlinkapi/pods.go')
-rw-r--r--pkg/varlinkapi/pods.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go
index 4ca4c4270..c79cee4c2 100644
--- a/pkg/varlinkapi/pods.go
+++ b/pkg/varlinkapi/pods.go
@@ -2,6 +2,7 @@ package varlinkapi
import (
"encoding/json"
+ "fmt"
"github.com/containers/libpod/pkg/adapter/shortcuts"
"github.com/containers/libpod/pkg/rootless"
"syscall"
@@ -299,3 +300,33 @@ func (i *LibpodAPI) PodStateData(call iopodman.VarlinkCall, name string) error {
}
return call.ReplyPodStateData(string(b))
}
+
+// TopPod provides the top stats for a given or latest pod
+func (i *LibpodAPI) TopPod(call iopodman.VarlinkCall, name string, latest bool, descriptors []string) error {
+ var (
+ pod *libpod.Pod
+ err error
+ )
+ if latest {
+ name = "latest"
+ pod, err = i.Runtime.GetLatestPod()
+ } else {
+ pod, err = i.Runtime.LookupPod(name)
+ }
+ if err != nil {
+ return call.ReplyPodNotFound(name, err.Error())
+ }
+
+ podStatus, err := shared.GetPodStatus(pod)
+ if err != nil {
+ return call.ReplyErrorOccurred(fmt.Sprintf("unable to get status for pod %s", pod.ID()))
+ }
+ if podStatus != "Running" {
+ return call.ReplyErrorOccurred("pod top can only be used on pods with at least one running container")
+ }
+ reply, err := pod.GetPodPidInformation(descriptors)
+ if err != nil {
+ return call.ReplyErrorOccurred(err.Error())
+ }
+ return call.ReplyTopPod(reply)
+}