From 0a78472211cc187d554189115afeb71e0ca076e1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 27 Sep 2017 18:05:51 +0200 Subject: [PATCH] Update default output format for stats to include ID and Name The `docker container stats` output has a column (`CONTAINER`), that shows either the container _id_ or container _name_, depending on the arguments given. For example, running `docker container stats foobar` shows: CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS foobar 0.00% 1.938MiB / 1.952GiB 0.10% 782B / 0B 4.11MB / 0B 2 Whereas `docker container stats 67b2525d8ad1` (`67b2525d8ad1` being the ID for container `foobar`) shows: CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 67b2525d8ad1 0.00% 1.938MiB / 1.952GiB 0.10% 916B / 0B 4.11MB / 0B 2 This behavior is confusing. This patch updates the default output format for `docker stats` to use separate columns for container ID and container Name (similar to `docker container ls`). With this patch applied, both commands show the same output: $ docker container stats foobar CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 67b2525d8ad10bb236a49960e93c09993b0baabeef12c2d46cd5f4fbb6f4808c foobar 0.00% 1.938MiB / 1.952GiB 0.10% 1.25kB / 0B 4.11MB / 0B 2 $ docker container stats 67b2525d8ad1 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 67b2525d8ad10bb236a49960e93c09993b0baabeef12c2d46cd5f4fbb6f4808c foobar 0.00% 1.938MiB / 1.952GiB 0.10% 1.31kB / 0B 4.11MB / 0B 2 Users that want to use the old format can configure a custom format in the cli configuration file (`~/.docker/config.json`); on Linux: { "statsFormat" : "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}" } on Windows: { "statsFormat" : "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" } Signed-off-by: Sebastiaan van Stijn --- cli/command/formatter/stats.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/command/formatter/stats.go b/cli/command/formatter/stats.go index 06eedc7158..58a5345055 100644 --- a/cli/command/formatter/stats.go +++ b/cli/command/formatter/stats.go @@ -9,8 +9,8 @@ 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}}" + defaultStatsTableFormat = "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}" + winDefaultStatsTableFormat = "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" containerHeader = "CONTAINER" cpuPercHeader = "CPU %"