From 0e3846e280195cb47c47a7739b475b281dd301cb Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Tue, 5 Apr 2016 19:30:35 +0000 Subject: [PATCH] Change HumanSize to BytesSize for memory output in `docker stats`. This fix tries to fix the discrepancy between `docker stats` and `docker run` where `docker run` uses RAMInBytes for all memory related inputs but `docker stats` uses HumanSize for all memory related outputs. To be consistent, `docker stats` needs to use BytesSize for all memory related outputs to conform to RAMInBytes in `docker run`. This fix addresses this issue. As BytesSize is used, the test cases needs to be adjusted to match `KiB/MiB/GiB` instead of `KB/MB/GB`. The documentation has also been updated. This fix fixes #21765. Signed-off-by: Yong Tang --- api/client/stats_helpers.go | 2 +- api/client/stats_unit_test.go | 2 +- docs/reference/commandline/stats.md | 10 +++++----- man/docker-stats.1.md | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/client/stats_helpers.go b/api/client/stats_helpers.go index 404c3ff196..697ee3e135 100644 --- a/api/client/stats_helpers.go +++ b/api/client/stats_helpers.go @@ -173,7 +173,7 @@ func (s *containerStats) Display(w io.Writer) error { fmt.Fprintf(w, "%s\t%.2f%%\t%s / %s\t%.2f%%\t%s / %s\t%s / %s\t%d\n", s.Name, s.CPUPercentage, - units.HumanSize(s.Memory), units.HumanSize(s.MemoryLimit), + units.BytesSize(s.Memory), units.BytesSize(s.MemoryLimit), s.MemoryPercentage, units.HumanSize(s.NetworkRx), units.HumanSize(s.NetworkTx), units.HumanSize(s.BlockRead), units.HumanSize(s.BlockWrite), diff --git a/api/client/stats_unit_test.go b/api/client/stats_unit_test.go index 36081c5772..b67a41f03f 100644 --- a/api/client/stats_unit_test.go +++ b/api/client/stats_unit_test.go @@ -27,7 +27,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\t104.9 MB / 838.9 MB\t1\n" + want := "app\t30.00%\t100 MiB / 2 GiB\t4.88%\t104.9 MB / 838.9 MB\t104.9 MB / 838.9 MB\t1\n" if got != want { t.Fatalf("c.Display() = %q, want %q", got, want) } diff --git a/docs/reference/commandline/stats.md b/docs/reference/commandline/stats.md index 8ef7d6e152..d46a94e3a2 100644 --- a/docs/reference/commandline/stats.md +++ b/docs/reference/commandline/stats.md @@ -28,13 +28,13 @@ Running `docker stats` on all running containers $ docker stats CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O - 1285939c1fd3 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B 3.568 MB / 512 KB - 9c76f7834ae2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B - d1ea048f04e4 0.03% 4.583 MB / 64 MB 6.30% 2.854 KB / 648 B 27.7 MB / 0 B + 1285939c1fd3 0.07% 796 KiB / 64 MiB 1.21% 788 B / 648 B 3.568 MB / 512 KB + 9c76f7834ae2 0.07% 2.746 MiB / 64 MiB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B + d1ea048f04e4 0.03% 4.583 MiB / 64 MiB 6.30% 2.854 KB / 648 B 27.7 MB / 0 B Running `docker stats` on multiple containers by name and id. $ docker stats fervent_panini 5acfcb1b4fd1 CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O - 5acfcb1b4fd1 0.00% 115.2 MB/1.045 GB 11.03% 1.422 kB/648 B - fervent_panini 0.02% 11.08 MB/1.045 GB 1.06% 648 B/648 B + 5acfcb1b4fd1 0.00% 115.2 MiB/1.045 GiB 11.03% 1.422 kB/648 B + fervent_panini 0.02% 11.08 MiB/1.045 GiB 1.06% 648 B/648 B diff --git a/man/docker-stats.1.md b/man/docker-stats.1.md index 520466b5b8..41c4b722a5 100644 --- a/man/docker-stats.1.md +++ b/man/docker-stats.1.md @@ -31,13 +31,13 @@ Running `docker stats` on all running containers $ docker stats CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O - 1285939c1fd3 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B 3.568 MB / 512 KB - 9c76f7834ae2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B - d1ea048f04e4 0.03% 4.583 MB / 64 MB 6.30% 2.854 KB / 648 B 27.7 MB / 0 B + 1285939c1fd3 0.07% 796 KiB / 64 MiB 1.21% 788 B / 648 B 3.568 MB / 512 KB + 9c76f7834ae2 0.07% 2.746 MiB / 64 MiB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B + d1ea048f04e4 0.03% 4.583 MiB / 64 MiB 6.30% 2.854 KB / 648 B 27.7 MB / 0 B Running `docker stats` on multiple containers by name and id. $ docker stats fervent_panini 5acfcb1b4fd1 CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O - 5acfcb1b4fd1 0.00% 115.2 MB/1.045 GB 11.03% 1.422 kB/648 B - fervent_panini 0.02% 11.08 MB/1.045 GB 1.06% 648 B/648 B + 5acfcb1b4fd1 0.00% 115.2 MiB/1.045 GiB 11.03% 1.422 kB/648 B + fervent_panini 0.02% 11.08 MiB/1.045 GiB 1.06% 648 B/648 B