Windows: stats support

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2016-09-07 16:08:51 -07:00
parent acb1fc424b
commit 86c86fc166
5 changed files with 14 additions and 11 deletions

View File

@ -1,15 +1,15 @@
package client
import (
"io"
"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) (io.ReadCloser, error) {
func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
query := url.Values{}
query.Set("stream", "0")
if stream {
@ -18,7 +18,9 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
if err != nil {
return nil, err
return types.ContainerStats{}, err
}
return resp.body, err
osType := GetDockerOS(resp.header.Get("Server"))
return types.ContainerStats{Body: resp.body, OSType: osType}, err
}

View File

@ -54,12 +54,12 @@ func TestContainerStats(t *testing.T) {
}, nil
}),
}
body, err := client.ContainerStats(context.Background(), "container_id", c.stream)
resp, err := client.ContainerStats(context.Background(), "container_id", c.stream)
if err != nil {
t.Fatal(err)
}
defer body.Close()
content, err := ioutil.ReadAll(body)
defer resp.Body.Close()
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}

View File

@ -39,7 +39,7 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
return types.ImageBuildResponse{}, err
}
osType := getDockerOS(serverResp.header.Get("Server"))
osType := GetDockerOS(serverResp.header.Get("Server"))
return types.ImageBuildResponse{
Body: serverResp.body,
@ -113,7 +113,8 @@ func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, erro
return query, nil
}
func getDockerOS(serverHeader string) string {
// GetDockerOS returns the operating system based on the server header from the daemon.
func GetDockerOS(serverHeader string) string {
var osType string
matches := headerRegexp.FindStringSubmatch(serverHeader)
if len(matches) > 0 {

View File

@ -222,7 +222,7 @@ func TestGetDockerOS(t *testing.T) {
"Foo/v1.22 (bar)": "",
}
for header, os := range cases {
g := getDockerOS(header)
g := GetDockerOS(header)
if g != os {
t.Fatalf("Expected %s, got %s", os, g)
}

View File

@ -51,7 +51,7 @@ type ContainerAPIClient interface {
ContainerResize(ctx context.Context, container string, options types.ResizeOptions) error
ContainerRestart(ctx context.Context, container string, timeout *time.Duration) error
ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error)
ContainerStats(ctx context.Context, container string, stream bool) (io.ReadCloser, error)
ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error)
ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
ContainerStop(ctx context.Context, container string, timeout *time.Duration) error
ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error)