docker stats命令

栏目: Docker 发布时间:2024-12-05
docker stats

options

Name, shorthand Description
--all , -a Show all containers (default shows just running)
--format Pretty-print images using a Go template
--no-stream Disable streaming stats and only pull the first result
--no-trunc Do not truncate output

如果不指定 --format,docker stats 默认会展示下面几列:

Column name Description
CONTAINER ID and Name the ID and name of the container
CPU % and MEM % the percentage of the host’s CPU and memory the container is using
MEM USAGE / LIMIT the total memory the container is using, and the total amount of memory it is allowed to use
NET I/O The amount of data the container has sent and received over its network interface
BLOCK I/O The amount of data the container has read to and written from block devices on the host
PIDs the number of processes or threads the container has created

docker stats 示例:

$ docker stats
CONTAINER ID        NAME                     CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
c395f63bff12        fe-node                  0.00%               112KiB / 15.51GiB     0.00%               5.39kB / 5.04kB     25.3MB / 0B         1
e05a642ecc50        febranchswitcher_web_1   0.00%               28.2MiB / 15.51GiB    0.18%               1.82MB / 551kB      24.6MB / 16.4kB     20
f100f6e78dc1        fe-redis                 0.14%               1.969MiB / 15.51GiB   0.01%               111MB / 26.1MB      2.03GB / 2.67MB     5
CONTAINER ID        NAME                     CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
c395f63bff12        fe-node                  0.00%               128KiB / 15.51GiB     0.00%               5.39kB / 5.04kB     25.3MB / 0B         1
e05a642ecc50        febranchswitcher_web_1   0.00%               28.2MiB / 15.51GiB    0.18%               1.82MB / 551kB      24.6MB / 16.4kB     20
f100f6e78dc1        fe-redis                 0.16%               1.969MiB / 15.51GiB   0.01%               111MB / 26.1MB      2.03GB / 2.67MB     5
CONTAINER ID        NAME                     CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS

使用 docker stats 查看指定容器的统计数据

docker stats 容器 id 或容器名称

示例:

$ docker stats fe-node
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
bf9c25d06c78        fe-node             0.00%               132KiB / 15.51GiB   0.00%               8.02kB / 7.49kB     6.92MB / 4.1kB      1
$ docker stats bf9c25d06c78
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
bf9c25d06c78        fe-node             0.00%               132KiB / 15.51GiB   0.00%               8.02kB / 7.49kB     6.92MB / 4.1kB      1

--format

Placeholder Description
.Container Container name or ID (user input)
.Name Container name
.ID Container ID
.CPUPerc CPU percentage
.MemUsage Memory usage
.NetIO Network IO
.BlockIO Block IO
.MemPerc Memory percentage (Not available on Windows)
.PIDs Number of PIDs (Not available on Windows)
$ docker stats --format "{{.Container}}: {{.CPUPerc}}"
bf9c25d06c78: 0.00%
e05a642ecc50: 0.00%
f100f6e78dc1: 0.13%

本文地址:https://www.tides.cn/p_docker-stats

标签: docker stats