From dff7842790555b7862f1bc32d2f932f8a36a18c4 Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 25 Oct 2016 16:19:14 -0700 Subject: [PATCH] Windows: Fix stats CLI Signed-off-by: John Howard --- command/container/stats.go | 11 ++++++++++- command/formatter/stats.go | 33 ++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/command/container/stats.go b/command/container/stats.go index 4d35e744c2..e7954e4b98 100644 --- a/command/container/stats.go +++ b/command/container/stats.go @@ -80,6 +80,16 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { } } + // Get the daemonOSType if not set already + if daemonOSType == "" { + svctx := context.Background() + sv, err := dockerCli.Client().ServerVersion(svctx) + if err != nil { + return err + } + daemonOSType = sv.Os + } + // waitFirst is a WaitGroup to wait first stat data's reach for each container waitFirst := &sync.WaitGroup{} @@ -184,7 +194,6 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { Output: dockerCli.Out(), Format: formatter.NewStatsFormat(f, daemonOSType), } - cleanScreen := func() { if !opts.noStream { fmt.Fprint(dockerCli.Out(), "\033[2J") diff --git a/command/formatter/stats.go b/command/formatter/stats.go index 212a1b4f5e..cc2588c392 100644 --- a/command/formatter/stats.go +++ b/command/formatter/stats.go @@ -10,17 +10,16 @@ import ( const ( winOSType = "windows" defaultStatsTableFormat = "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}" - winDefaultStatsTableFormat = "table {{.Container}}\t{{.CPUPerc}}\t{{{.MemUsage}}\t{.NetIO}}\t{{.BlockIO}}" - emptyStatsTableFormat = "Waiting for statistics..." + winDefaultStatsTableFormat = "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" - containerHeader = "CONTAINER" - cpuPercHeader = "CPU %" - netIOHeader = "NET I/O" - blockIOHeader = "BLOCK I/O" - winMemPercHeader = "PRIV WORKING SET" // Used only on Window - memPercHeader = "MEM %" // Used only on Linux - memUseHeader = "MEM USAGE / LIMIT" // Used only on Linux - pidsHeader = "PIDS" // Used only on Linux + containerHeader = "CONTAINER" + cpuPercHeader = "CPU %" + netIOHeader = "NET I/O" + blockIOHeader = "BLOCK I/O" + memPercHeader = "MEM %" // Used only on Linux + winMemUseHeader = "PRIV WORKING SET" // Used only on Windows + memUseHeader = "MEM USAGE / LIMIT" // Used only on Linux + pidsHeader = "PIDS" // Used only on Linux ) // StatsEntry represents represents the statistics data collected from a container @@ -151,18 +150,22 @@ func (c *containerStatsContext) CPUPerc() string { } func (c *containerStatsContext) MemUsage() string { - c.AddHeader(memUseHeader) - if c.s.IsInvalid || c.s.OSType == winOSType { + header := memUseHeader + if c.s.OSType == winOSType { + header = winMemUseHeader + } + c.AddHeader(header) + if c.s.IsInvalid { return fmt.Sprintf("-- / --") } + if c.s.OSType == winOSType { + return fmt.Sprintf("%s", units.BytesSize(c.s.Memory)) + } return fmt.Sprintf("%s / %s", units.BytesSize(c.s.Memory), units.BytesSize(c.s.MemoryLimit)) } func (c *containerStatsContext) MemPerc() string { header := memPercHeader - if c.s.OSType == winOSType { - header = winMemPercHeader - } c.AddHeader(header) if c.s.IsInvalid { return fmt.Sprintf("--")