2016-09-06 21:46:37 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
2016-09-08 02:08:51 +03:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-09-06 21:46:37 +03:00
|
|
|
"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.
|
2016-09-08 02:08:51 +03:00
|
|
|
func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
|
2016-09-06 21:46:37 +03:00
|
|
|
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 {
|
2016-09-08 02:08:51 +03:00
|
|
|
return types.ContainerStats{}, err
|
2016-09-06 21:46:37 +03:00
|
|
|
}
|
2016-09-08 02:08:51 +03:00
|
|
|
|
2016-11-10 01:46:53 +03:00
|
|
|
osType := getDockerOS(resp.header.Get("Server"))
|
2016-09-08 02:08:51 +03:00
|
|
|
return types.ContainerStats{Body: resp.body, OSType: osType}, err
|
2016-09-06 21:46:37 +03:00
|
|
|
}
|