Multiple fixes to 'docker stats' output:

* Add space between values in docker stats output for easier parsing

  Old output could not be parsed easily because there were columns
  that did not have any separator. Also values that are together
  without any space is difficult to read even for humans.

* Update unit.HumanSize comment to match what the does actually does

Signed-off-by: Otto Kekäläinen <otto@seravo.fi>
This commit is contained in:
Otto Kekäläinen 2015-07-29 14:12:57 +03:00
parent c19a00d4cb
commit b619220ce1
6 changed files with 15 additions and 16 deletions

View file

@ -110,7 +110,7 @@ func (s *containerStats) Display(w io.Writer) error {
if s.err != nil {
return s.err
}
fmt.Fprintf(w, "%s\t%.2f%%\t%s/%s\t%.2f%%\t%s/%s\n",
fmt.Fprintf(w, "%s\t%.2f%%\t%s / %s\t%.2f%%\t%s / %s\n",
s.Name,
s.CPUPercentage,
units.HumanSize(s.Memory), units.HumanSize(s.MemoryLimit),
@ -142,7 +142,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
fmt.Fprint(cli.out, "\033[2J")
fmt.Fprint(cli.out, "\033[H")
}
io.WriteString(w, "CONTAINER\tCPU %\tMEM USAGE/LIMIT\tMEM %\tNET I/O\n")
io.WriteString(w, "CONTAINER\tCPU %\tMEM USAGE / LIMIT\tMEM %\tNET I/O\n")
}
for _, n := range names {
s := &containerStats{Name: n}

View file

@ -22,7 +22,7 @@ func TestDisplay(t *testing.T) {
t.Fatalf("c.Display() gave error: %s", err)
}
got := b.String()
want := "app\t30.00%\t104.9 MB/2.147 GB\t4.88%\t104.9 MB/838.9 MB\n"
want := "app\t30.00%\t104.9 MB / 2.147 GB\t4.88%\t104.9 MB / 838.9 MB\n"
if got != want {
t.Fatalf("c.Display() = %q, want %q", got, want)
}

View file

@ -21,13 +21,13 @@ and network IO metrics.
The following is a sample output from the `docker stats` command
$ docker stats redis1 redis2
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
redis1 0.07% 796 KB/64 MB 1.21% 788 B/648 B
redis2 0.07% 2.746 MB/64 MB 4.29% 1.266 KB/648 B
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B
The [docker stats](/reference/commandline/stats/) reference page has
more details about the `docker stats` command.
more details about the `docker stats` command.
## Control groups

View file

@ -21,9 +21,9 @@ weight=1
Running `docker stats` on multiple containers
$ docker stats redis1 redis2
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
redis1 0.07% 796 KB/64 MB 1.21% 788 B/648 B
redis2 0.07% 2.746 MB/64 MB 4.29% 1.266 KB/648 B
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B
The `docker stats` command will only return a live stream of data for running
@ -31,4 +31,4 @@ containers. Stopped containers will not return any data.
> **Note:**
> If you want more detailed information about a container's resource
> usage, use the API endpoint.
> usage, use the API endpoint.

View file

@ -25,7 +25,6 @@ Display a live stream of one or more containers' resource usage statistics
Run **docker stats** with multiple containers.
$ docker stats redis1 redis2
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
redis1 0.07% 796 KB/64 MB 1.21% 788 B/648 B
redis2 0.07% 2.746 MB/64 MB 4.29% 1.266 KB/648 B
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B

View file

@ -49,7 +49,7 @@ func CustomSize(format string, size float64, base float64, _map []string) string
}
// HumanSize returns a human-readable approximation of a size
// using SI standard (eg. "44kB", "17MB").
// capped at 4 valid numbers (eg. "2.746 MB", "796 KB").
func HumanSize(size float64) string {
return CustomSize("%.4g %s", size, 1000.0, decimapAbbrs)
}