container_top.go 698 B

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