Commit 5fb5e0b
committed
docker stats --all: remove containers when removed
Before this patch, running `docker stats --all` would continue showing
all containers once observed. For example;
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.12kB / 126B 0B / 12.3kB 11
fc191b27517f foo2 0.00% 8.531MiB / 7.653GiB 0.11% 998B / 126B 0B / 12.3kB 11
5040185fba53 foo3 0.00% 8.578MiB / 7.653GiB 0.11% 872B / 126B 0B / 8.19kB 11
WHen removing `foo2`, the container would continue to be listed:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.12kB / 126B 0B / 12.3kB 11
fc191b27517f foo2 -- -- / -- -- -- -- --
5040185fba53 foo3 0.00% 8.578MiB / 7.653GiB 0.11% 872B / 126B 0B / 12.3kB 11
Starting a new `foo2` container would now produce multiple entries:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.25kB / 126B 0B / 12.3kB 11
fc191b27517f foo2 -- -- / -- -- -- -- --
5040185fba53 foo3 0.00% 8.578MiB / 7.653GiB 0.11% 998B / 126B 0B / 12.3kB 11
dba11b9e1ba9 foo2 0.00% 8.578MiB / 7.653GiB 0.11% 872B / 126B 0B / 8.19kB 11
Repeat that, and the list would continue to grow;
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.25kB / 126B 0B / 12.3kB 11
fc191b27517f foo2 -- -- / -- -- -- -- --
5040185fba53 foo3 0.00% 8.578MiB / 7.653GiB 0.11% 998B / 126B 0B / 12.3kB 11
dba11b9e1ba9 foo2 -- -- / -- -- -- -- --
193a6dcfaa2d foo2 -- -- / -- -- -- -- --
bf50e58085c6 foo2 0.00% 8.539MiB / 7.653GiB 0.11% 872B / 126B 0B / 8.19kB 11
After this patch, containers are removed when we observe a `destroy` event;
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.5kB / 126B 0B / 12.3kB 11
5040185fba53 foo3 0.00% 8.578MiB / 7.653GiB 0.11% 1.25kB / 126B 0B / 12.3kB 11
bf50e58085c6 foo2 0.00% 8.539MiB / 7.653GiB 0.11% 872B / 126B 0B / 12.3kB 11
Containers are added when created, so in the example above, the new `foo2`
is added at the end:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.5kB / 126B 0B / 12.3kB 11
5040185fba53 foo3 0.00% 8.578MiB / 7.653GiB 0.11% 1.25kB / 126B 0B / 12.3kB 11
bf50e58085c6 foo2 0.00% 8.539MiB / 7.653GiB 0.11% 872B / 126B 0B / 12.3kB 11
If a container dies, and `--all` is set, we continue listing it, but stats
are not updated while the container is stopped (we should consider resetting
the stats and show `-- / --` to be more clear that we don't have the container
running).
Here's with `foo3` stopped:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.5kB / 126B 0B / 12.3kB 11
5040185fba53 foo3 0.00% 0B / 0B 0.00% 0B / 0B 0B / 0B 0
bf50e58085c6 foo2 0.00% 8.539MiB / 7.653GiB 0.11% 872B / 126B 0B / 12.3kB 11
Starting the container continues updating its stats:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f2a785b0cd5f foo1 0.00% 8.535MiB / 7.653GiB 0.11% 1.63kB / 126B 0B / 12.3kB 11
5040185fba53 foo3 0.00% 8.496MiB / 7.653GiB 0.11% 872B / 126B 0B / 0B 11
bf50e58085c6 foo2 0.00% 8.539MiB / 7.653GiB 0.11% 998B / 126B 0B / 12.3kB 11
When running without `--all`, we continue to remove containers as soon as
possible (`die` events), but with `--all`, those events are ignored with
the expectation that the container might come back.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>1 parent 743c385 commit 5fb5e0b
1 file changed
+12
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
159 | 166 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 167 | + | |
164 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
165 | 173 | | |
166 | 174 | | |
167 | 175 | | |
| |||
0 commit comments