mirror of
https://github.com/moby/moby.git
synced 2026-07-12 18:45:06 +00:00
commit17c3269a37moved the ContainerStats type to the container package, and renamed it to StatsResponse. However, this name is chosen poorly, as it documents it to be the response of the API endpoint, but is more accurately a wrapper around a reader, used to read a (stream of) StatsJSON. We want to change StatsJSON to StatsResponse, as it's more consistent with other response types. As17c3269a37did not make it into a non-pre-release, we can still change this. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package client // import "github.com/docker/docker/client"
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
)
|
|
|
|
// 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) (container.StatsResponseReader, 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 container.StatsResponseReader{}, err
|
|
}
|
|
|
|
return container.StatsResponseReader{
|
|
Body: resp.body,
|
|
OSType: getDockerOS(resp.header.Get("Server")),
|
|
}, nil
|
|
}
|
|
|
|
// ContainerStatsOneShot gets a single stat entry from a container.
|
|
// It differs from `ContainerStats` in that the API should not wait to prime the stats
|
|
func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (container.StatsResponseReader, error) {
|
|
query := url.Values{}
|
|
query.Set("stream", "0")
|
|
query.Set("one-shot", "1")
|
|
|
|
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
|
|
if err != nil {
|
|
return container.StatsResponseReader{}, err
|
|
}
|
|
|
|
return container.StatsResponseReader{
|
|
Body: resp.body,
|
|
OSType: getDockerOS(resp.header.Get("Server")),
|
|
}, nil
|
|
}
|