docker stats 命令用來返回運行中的容器的實時數據流。
通過--help查看使用說明:
~]# docker stats --help Usage: docker stats [OPTIONS] [CONTAINER...] Display a live stream of container(s) resource usage statistics Options: -a, --all Show all containers (default shows just running) --format string Pretty-print images using a Go template --help Print usage --no-stream Disable streaming stats and only pull the first result
示例:
01》 docker stats
~]# docker stats CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 10427e190c59 0.00% 15.94MiB / 47.01GiB 0.03% 0B / 0B 0B / 0B 0 39cb0a19e07e 0.06% 928KiB / 47.01GiB 0.00% 693MB / 683MB 0B / 0B 0 ce9db3c0e256 0.00% 80.83MiB / 47.01GiB 0.17% 0B / 0B 0B / 0B 0
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 10427e190c59 0.16% 15.94MiB / 47.01GiB 0.03% 0B / 0B 0B / 0B 0 39cb0a19e07e 0.03% 928KiB / 47.01GiB 0.00% 693MB / 683MB 0B / 0B 0 ce9db3c0e256 0.06% 80.73MiB / 47.01GiB 0.17% 0B / 0B 0B / 0B 0
默認情況下,stats 使用參數-a或者--all,命令會每隔 1 秒鍾刷新一次輸出的內容直到你按下 ctrl + c。下面是輸出的主要內容:
[CONTAINER]:以短格式顯示容器的 ID。
[CPU %]:CPU 的使用情況。
[MEM USAGE / LIMIT]:當前使用的內存和最大可以使用的內存。
[MEM %]:以百分比的形式顯示內存使用情況。
[NET I/O]:網絡 I/O 數據。
[BLOCK I/O]:磁盤 I/O 數據。
[PIDS]:PID 號。
如果不想持續的監控容器使用資源的情況,可以通過 --no-stream 選項只輸出當前的狀態:
~]# docker stats --no-stream CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 10427e190c59 0.00% 15.94MiB / 47.01GiB 0.03% 0B / 0B 0B / 0B 0 39cb0a19e07e 0.06% 928KiB / 47.01GiB 0.00% 693MB / 683MB 0B / 0B 0 ce9db3c0e256 0.00% 80.83MiB / 47.01GiB 0.17% 0B / 0B 0B / 0B 0
02》docker stats [container]
~]# docker stats ca2f272bd780 CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS ca2f272bd780 0.00% 21.12MiB / 47.01GiB 0.04% 103GB / 5.06TB 0B / 66.8GB 0
03》docker stats --format
~]# docker stats --all --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" CONTAINER CPU % MEM USAGE / LIMIT 10427e190c59 0.01% 15.94MiB / 47.01GiB 39cb0a19e07e 0.13% 928KiB / 47.01GiB ce9db3c0e256 0.00% 80.8MiB / 47.01GiB
~]# docker stats --all --format "table {{.Container}}***{{.CPUPerc}}***{{.MemUsage}}" CONTAINER***CPU %***MEM USAGE / LIMIT 10427e190c59***0.08%***15.94MiB / 47.01GiB 39cb0a19e07e***0.03%***928KiB / 47.01GiB ce9db3c0e256***0.00%***81.3MiB / 47.01GiB
