mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
d8dcbf3ec3
Signed-off-by: John Howard <jhoward@microsoft.com>
26 lines
703 B
Go
26 lines
703 B
Go
package client
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"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.
|
|
func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
|
|
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 {
|
|
return types.ContainerStats{}, err
|
|
}
|
|
|
|
osType := getDockerOS(resp.header.Get("Server"))
|
|
return types.ContainerStats{Body: resp.body, OSType: osType}, err
|
|
}
|