From b619220ce11770ffaea068b54d3975c74f7c24f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Wed, 29 Jul 2015 14:12:57 +0300 Subject: [PATCH] Multiple fixes to 'docker stats' output: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- api/client/stats.go | 4 ++-- api/client/stats_unit_test.go | 2 +- docs/articles/runmetrics.md | 8 ++++---- docs/reference/commandline/stats.md | 8 ++++---- man/docker-stats.1.md | 7 +++---- pkg/units/size.go | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/api/client/stats.go b/api/client/stats.go index 1feb1e11b7..334dc5417e 100644 --- a/api/client/stats.go +++ b/api/client/stats.go @@ -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} diff --git a/api/client/stats_unit_test.go b/api/client/stats_unit_test.go index 0831dbcbbe..b2db75a199 100644 --- a/api/client/stats_unit_test.go +++ b/api/client/stats_unit_test.go @@ -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) } diff --git a/docs/articles/runmetrics.md b/docs/articles/runmetrics.md index 0be55b4e4b..d02f1d6806 100644 --- a/docs/articles/runmetrics.md +++ b/docs/articles/runmetrics.md @@ -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 diff --git a/docs/reference/commandline/stats.md b/docs/reference/commandline/stats.md index 7e67099e0e..6ee026a75f 100644 --- a/docs/reference/commandline/stats.md +++ b/docs/reference/commandline/stats.md @@ -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. \ No newline at end of file +> usage, use the API endpoint. diff --git a/man/docker-stats.1.md b/man/docker-stats.1.md index 4b48588559..08502f44a5 100644 --- a/man/docker-stats.1.md +++ b/man/docker-stats.1.md @@ -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 diff --git a/pkg/units/size.go b/pkg/units/size.go index 2fde3b412a..3b59daff31 100644 --- a/pkg/units/size.go +++ b/pkg/units/size.go @@ -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) }