client/container_stats.go
7c36a1af
 package client
 
 import (
 	"net/url"
 
340e5233
 	"github.com/docker/docker/api/types"
7c36a1af
 	"golang.org/x/net/context"
 )
 
 // ContainerStats returns near realtime stats for a given container.
 // It's up to the caller to close the io.ReadCloser returned.
340e5233
 func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
7c36a1af
 	query := url.Values{}
 	query.Set("stream", "0")
 	if stream {
 		query.Set("stream", "1")
 	}
 
 	resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
 	if err != nil {
340e5233
 		return types.ContainerStats{}, err
7c36a1af
 	}
340e5233
 
d8dcbf3e
 	osType := getDockerOS(resp.header.Get("Server"))
340e5233
 	return types.ContainerStats{Body: resp.body, OSType: osType}, err
7c36a1af
 }