github.com/brandon-bethke-neudesic/moby@v1.13.1/client/container_top.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/url"
     6  	"strings"
     7  
     8  	"github.com/docker/docker/api/types"
     9  	"golang.org/x/net/context"
    10  )
    11  
    12  // ContainerTop shows process information from within a container.
    13  func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (types.ContainerProcessList, error) {
    14  	var response types.ContainerProcessList
    15  	query := url.Values{}
    16  	if len(arguments) > 0 {
    17  		query.Set("ps_args", strings.Join(arguments, " "))
    18  	}
    19  
    20  	resp, err := cli.get(ctx, "/containers/"+containerID+"/top", query, nil)
    21  	if err != nil {
    22  		return response, err
    23  	}
    24  
    25  	err = json.NewDecoder(resp.body).Decode(&response)
    26  	ensureReaderClosed(resp)
    27  	return response, err
    28  }