container_stats.go 550 B

12345678910111213141516171819202122232425
  1. package client
  2. import (
  3. "io"
  4. "net/url"
  5. "golang.org/x/net/context"
  6. )
  7. // ContainerStats returns near realtime stats for a given container.
  8. // It's up to the caller to close the io.ReadCloser returned.
  9. func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (io.ReadCloser, error) {
  10. query := url.Values{}
  11. query.Set("stream", "0")
  12. if stream {
  13. query.Set("stream", "1")
  14. }
  15. resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return resp.body, err
  20. }