container_top.go 647 B

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