github.com/vvnotw/moby@v1.13.1/client/container_stats.go (about)

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