container_stats.go 703 B

1234567891011121314151617181920212223242526
  1. package client
  2. import (
  3. "net/url"
  4. "github.com/docker/docker/api/types"
  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) (types.ContainerStats, 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 types.ContainerStats{}, err
  18. }
  19. osType := getDockerOS(resp.header.Get("Server"))
  20. return types.ContainerStats{Body: resp.body, OSType: osType}, err
  21. }