mirror of https://github.com/docker/cli.git
Windows: Fix stats CLI
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
d5d520f0d7
commit
dff7842790
|
@ -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 is a WaitGroup to wait first stat data's reach for each container
|
||||||
waitFirst := &sync.WaitGroup{}
|
waitFirst := &sync.WaitGroup{}
|
||||||
|
|
||||||
|
@ -184,7 +194,6 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
|
||||||
Output: dockerCli.Out(),
|
Output: dockerCli.Out(),
|
||||||
Format: formatter.NewStatsFormat(f, daemonOSType),
|
Format: formatter.NewStatsFormat(f, daemonOSType),
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanScreen := func() {
|
cleanScreen := func() {
|
||||||
if !opts.noStream {
|
if !opts.noStream {
|
||||||
fmt.Fprint(dockerCli.Out(), "\033[2J")
|
fmt.Fprint(dockerCli.Out(), "\033[2J")
|
||||||
|
|
|
@ -10,17 +10,16 @@ import (
|
||||||
const (
|
const (
|
||||||
winOSType = "windows"
|
winOSType = "windows"
|
||||||
defaultStatsTableFormat = "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"
|
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}}"
|
winDefaultStatsTableFormat = "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}"
|
||||||
emptyStatsTableFormat = "Waiting for statistics..."
|
|
||||||
|
|
||||||
containerHeader = "CONTAINER"
|
containerHeader = "CONTAINER"
|
||||||
cpuPercHeader = "CPU %"
|
cpuPercHeader = "CPU %"
|
||||||
netIOHeader = "NET I/O"
|
netIOHeader = "NET I/O"
|
||||||
blockIOHeader = "BLOCK I/O"
|
blockIOHeader = "BLOCK I/O"
|
||||||
winMemPercHeader = "PRIV WORKING SET" // Used only on Window
|
memPercHeader = "MEM %" // Used only on Linux
|
||||||
memPercHeader = "MEM %" // Used only on Linux
|
winMemUseHeader = "PRIV WORKING SET" // Used only on Windows
|
||||||
memUseHeader = "MEM USAGE / LIMIT" // Used only on Linux
|
memUseHeader = "MEM USAGE / LIMIT" // Used only on Linux
|
||||||
pidsHeader = "PIDS" // Used only on Linux
|
pidsHeader = "PIDS" // Used only on Linux
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatsEntry represents represents the statistics data collected from a container
|
// StatsEntry represents represents the statistics data collected from a container
|
||||||
|
@ -151,18 +150,22 @@ func (c *containerStatsContext) CPUPerc() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *containerStatsContext) MemUsage() string {
|
func (c *containerStatsContext) MemUsage() string {
|
||||||
c.AddHeader(memUseHeader)
|
header := memUseHeader
|
||||||
if c.s.IsInvalid || c.s.OSType == winOSType {
|
if c.s.OSType == winOSType {
|
||||||
|
header = winMemUseHeader
|
||||||
|
}
|
||||||
|
c.AddHeader(header)
|
||||||
|
if c.s.IsInvalid {
|
||||||
return fmt.Sprintf("-- / --")
|
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))
|
return fmt.Sprintf("%s / %s", units.BytesSize(c.s.Memory), units.BytesSize(c.s.MemoryLimit))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *containerStatsContext) MemPerc() string {
|
func (c *containerStatsContext) MemPerc() string {
|
||||||
header := memPercHeader
|
header := memPercHeader
|
||||||
if c.s.OSType == winOSType {
|
|
||||||
header = winMemPercHeader
|
|
||||||
}
|
|
||||||
c.AddHeader(header)
|
c.AddHeader(header)
|
||||||
if c.s.IsInvalid {
|
if c.s.IsInvalid {
|
||||||
return fmt.Sprintf("--")
|
return fmt.Sprintf("--")
|
||||||
|
|
Loading…
Reference in New Issue