summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_top_linux.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go
index 9b0f156b5..b370495fe 100644
--- a/libpod/container_top_linux.go
+++ b/libpod/container_top_linux.go
@@ -7,8 +7,22 @@ import (
"strings"
"github.com/containers/psgo"
+ "github.com/pkg/errors"
)
+// Top gathers statistics about the running processes in a container. It returns a
+// []string for output
+func (c *Container) Top(descriptors []string) ([]string, error) {
+ conStat, err := c.State()
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to look up state for %s", c.ID())
+ }
+ if conStat != ContainerStateRunning {
+ return nil, errors.Errorf("top can only be used on running containers")
+ }
+ return c.GetContainerPidInformation(descriptors)
+}
+
// GetContainerPidInformation returns process-related data of all processes in
// the container. The output data can be controlled via the `descriptors`
// argument which expects format descriptors and supports all AIXformat