作者: 耗子007
所有命令均基于docker1.11版本
这里主要分析容器维测相关的几个命令:
- stats:获取容器资源使用状态
- top:容器内运行进程信息
容器资源状态
1 2 3 4 5 6 7
| Usage: docker stats [OPTIONS] [CONTAINER...]
Display a live stream of one or more containers’ resource usage statistics
-a, --all Show all containers (default shows just running) --help Print usage --no-stream Disable streaming stats and only pull the first result
|
stats命令会返回一个持续的容器资源统计数据流,可以通过指定一些容器ID或者name来限制检测的数量。
注:
- 你可以指定一个停止的容器,但是不会返回任何数据。
- 更详细的统计数据可以通过/containers/(id)/stats API获取
例如,获取所有运行的容器资源数据:
1 2 3 4 5
| $ 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
|
容器内进程信息
1 2 3 4 5
| Usage: docker top [OPTIONS] CONTAINER [ps OPTIONS]
Display the running processes of a container
--help Print usage
|
top命令会显示容器内运行进程的一些信息,例如:
1 2 3 4 5 6
| UID PID PPID C STIME TTY TIME CMD root 3999 3983 0 Feb25 pts/24 00:00:00 /bin/sh -c hexo generate && hexo server root 4097 3999 0 Feb25 pts/24 00:12:31 hexo root 17660 17644 0 Feb27 pts/30 00:00:00 /bin/bash root 28408 28392 0 Feb27 pts/31 00:00:00 /bin/bash
|
注意:top只会返回一次结果,和stats的结果不一样。