container_stats.go 492 B

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