From c4dd7c5813078acbe871aae37644bfff3163d160 Mon Sep 17 00:00:00 2001 From: baude Date: Wed, 24 Apr 2019 15:57:37 -0500 Subject: enable podman remote top add the ability for the remote client to display a container's running processes. Signed-off-by: baude --- libpod/container_top_linux.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libpod') 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 -- cgit v1.2.3-54-g00ecf