container_top.go 745 B

12345678910111213141516171819202122232425262728
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/url"
  6. "strings"
  7. "github.com/docker/docker/api/types/container"
  8. )
  9. // ContainerTop shows process information from within a container.
  10. func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) {
  11. var response container.ContainerTopOKBody
  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. defer ensureReaderClosed(resp)
  18. if err != nil {
  19. return response, err
  20. }
  21. err = json.NewDecoder(resp.body).Decode(&response)
  22. return response, err
  23. }