当 Docker 部署规模逐步变大后,可视化监控容器环境的性能和健康状态会变得越来越重要。
 
在本章中,我们将学习几个目前比较常用的容器监控工具和方案,为以后构建自己的监控系统提供参考。
 
 
首先我们会讨论 Docker 自带的几个监控子命令:ps、top、stats。然后是几个功能更强的开源监控工具 sysdig、Weave Scope、cAdvisor 和 Prometheus 。最后我们在对这几个工具做一个对比。
 
docker container ps
 
查看当前运行的容器,下面三个命令的效果是完全一样的,加上 -a 可以查看没有运行的容器
 
root@host1:~# docker container ls --help
Usage:    docker container ls [OPTIONS]
List containers
Aliases:
  ls, ps, list
Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes
root@host1:~# docker container ps --help
Usage:    docker container ls [OPTIONS]
List containers
Aliases:
  ls, ps, list
Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes
root@host1:~# docker ps --help
Usage:    docker ps [OPTIONS]
List containers
Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes
 
root@host1:~# docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED              STATUS              PORTS               NAMES
b89ca1da78c3        busybox             "sh"                 About a minute ago   Up About a minute                       sad_sanderson
7874b10cb1d4        httpd               "httpd-foreground"   2 minutes ago        Up 2 minutes        80/tcp              keen_yalow
root@host1:~# docker container ps
CONTAINER ID        IMAGE               COMMAND              CREATED              STATUS              PORTS               NAMES
b89ca1da78c3        busybox             "sh"                 About a minute ago   Up About a minute                       sad_sanderson
7874b10cb1d4        httpd               "httpd-foreground"   2 minutes ago        Up 2 minutes        80/tcp              keen_yalow
root@host1:~# docker container ls
CONTAINER ID        IMAGE               COMMAND              CREATED              STATUS              PORTS               NAMES
b89ca1da78c3        busybox             "sh"                 About a minute ago   Up About a minute                       sad_sanderson
7874b10cb1d4        httpd               "httpd-foreground"   2 minutes ago        Up 2 minutes        80/tcp              keen_yalow
root@host1:~#
root@host1:~# docker ps -a
CONTAINER ID        IMAGE               COMMAND              CREATED              STATUS                          PORTS               NAMES
07373028ad05        busybox             "sh"                 About a minute ago   Exited (0) About a minute ago                       stoic_jepsen
b89ca1da78c3        busybox             "sh"                 About a minute ago   Up About a minute                                   sad_sanderson
7874b10cb1d4        httpd               "httpd-foreground"   2 minutes ago        Up 2 minutes                    80/tcp              keen_yalow
root@host1:~# docker container ps -a
CONTAINER ID        IMAGE               COMMAND              CREATED              STATUS                          PORTS               NAMES
07373028ad05        busybox             "sh"                 About a minute ago   Exited (0) About a minute ago                       stoic_jepsen
b89ca1da78c3        busybox             "sh"                 About a minute ago   Up About a minute                                   sad_sanderson
7874b10cb1d4        httpd               "httpd-foreground"   2 minutes ago        Up 2 minutes                    80/tcp              keen_yalow
root@host1:~# docker container ls -a
CONTAINER ID        IMAGE               COMMAND              CREATED              STATUS                          PORTS               NAMES
07373028ad05        busybox             "sh"                 About a minute ago   Exited (0) About a minute ago                       stoic_jepsen
b89ca1da78c3        busybox             "sh"                 2 minutes ago        Up 2 minutes                                        sad_sanderson
7874b10cb1d4        httpd               "httpd-foreground"   2 minutes ago        Up 2 minutes                    80/tcp              keen_yalow
 
docker container top container 
 
如果想知道某容器运行了哪些进程,可以执行 docker top
 
还可以在最后面跟上linux中ps的参数 -aux
 
root@host1:~# docker top --help
Usage:    docker top CONTAINER [ps OPTIONS]
Display the running processes of a container
 
root@host1:~# docker container top --help
Usage:    docker container top CONTAINER [ps OPTIONS]
Display the running processes of a container
 
root@host1:~# docker run -d --name lamp mattrayner/lamp
b67aded0f855a3d02c3b19539667a76ca88fe927d5ade9322d94f7cb0a0a0d82
 
root@host1:~# docker container top lamp
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                22808               22789               0                   09:26               ?                   00:00:00            /usr/bin/python /usr/bin/supervisord -n
root                23408               22808               0                   09:27               ?                   00:00:00            /bin/sh /usr/bin/mysqld_safe
root                23409               22808               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23811               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23812               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23815               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23817               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23818               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
999                 23826               23408               1                   09:27               ?                   00:00:00            /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 --log-syslog=1 --log-syslog-facility=daemon --log-syslog-tag=
root@host1:~# docker top lamp
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                22808               22789               0                   09:26               ?                   00:00:00            /usr/bin/python /usr/bin/supervisord -n
root                23408               22808               0                   09:27               ?                   00:00:00            /bin/sh /usr/bin/mysqld_safe
root                23409               22808               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23811               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23812               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23815               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23817               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
usera               23818               23409               0                   09:27               ?                   00:00:00            apache2 -D FOREGROUND
999                 23826               23408               1                   09:27               ?                   00:00:00            /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 --log-syslog=1 --log-syslog-facility=daemon --log-syslog-tag=
 
root@host1:~# docker top lamp -aux
USER                PID                 %CPU                %MEM                VSZ                 RSS                 TTY                 STAT                START               TIME                COMMAND
root                22808               0.1                 0.9                 51188               18704               ?                   Ss                  09:26               0:00                /usr/bin/python /usr/bin/supervisord -n
root                23408               0.0                 0.0                 4504                1632                ?                   S                   09:27               0:00                /bin/sh /usr/bin/mysqld_safe
root                23409               0.0                 1.5                 524236              32268               ?                   S                   09:27               0:00                apache2 -D FOREGROUND
usera               23811               0.0                 0.5                 524268              10496               ?                   S                   09:27               0:00                apache2 -D FOREGROUND
usera               23812               0.0                 0.5                 524268              10496               ?                   S                   09:27               0:00                apache2 -D FOREGROUND
usera               23815               0.0                 0.5                 524268              10496               ?                   S                   09:27               0:00                apache2 -D FOREGROUND
usera               23817               0.0                 0.5                 524268              10496               ?                   S                   09:27               0:00                apache2 -D FOREGROUND
usera               23818               0.0                 0.5                 524268              10496               ?                   S                   09:27               0:00                apache2 -D FOREGROUND
999                 23826               0.1                 10.1                1757648             207788              ?                   Sl                  09:27               0:00                /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 --log-syslog=1 --log-syslog-facility=daemon --log-syslog-tag=
 
 
docker container stats
 
该命令用于显示每个容器各种资源的使用情况,默认会显示一个实时变化的列表,展示每个容器的CPU、MEM的使用率和可用量,还有网络和IO的情况。
 
ps:容器启动时如果没有特别指定内存 limit 、stats命令会显示host的内存总量,但这并不意味着每个容器都能使用到这么多大的内存。
 
我们还可以查看指定容器的性能,只需在后面指定容器的名字即可,可以是一个,也可以是多个。
 
root@host1:~# 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
      --no-stream       Disable streaming stats and only pull the first result
      --no-trunc        Do not truncate output
root@host1:~# docker container stats --help
 
Usage:    docker container 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
      --no-stream       Disable streaming stats and only pull the first result
      --no-trunc        Do not truncate output
 
root@host1:~# docker container stats
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
b67aded0f855        lamp                0.04%               206.7MiB / 1.953GiB   10.34%              648B / 0B           4.61MB / 398MB      35
3c9c0f060dd0        admiring_bohr       0.04%               200.9MiB / 1.953GiB   10.05%              648B / 0B           60.6MB / 375MB      35
b89ca1da78c3        sad_sanderson       0.00%               56KiB / 1.953GiB      0.00%               648B / 0B           0B / 0B             1
7874b10cb1d4        keen_yalow          0.00%               7.566MiB / 1.953GiB   0.38%               1.3kB / 0B          0B / 0B             82
 
root@host1:~# docker container stats lamp admiring_bohr
 
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
b67aded0f855        lamp                0.04%               206.7MiB / 1.953GiB   10.34%              648B / 0B           4.61MB / 398MB      35
3c9c0f060dd0        admiring_bohr       0.04%               209.1MiB / 1.953GiB   10.45%              648B / 0B           60.6MB / 375MB      35
 
 
ps、top、stats这几个命令是docker 自带的,有点是运行方便,很适合想快速了解容器运行状态的场景。缺点是输出的数据有限,而且都是实时数据,无法反应历史变化和趋势。

078、Docker 最常用的监控方案(2019-04-25 周四)的更多相关文章

  1. 第 10 章 容器监控 - 078 - Docker 最常用的监控方案

    Docker 最常用的监控方案 当 Docker 部署规模逐步变大后,可视化监控容器环境的性能和健康状态将会变得越来越重要. Docker 自带的几个监控子命令: ps .top .stats 功能更 ...

  2. Docker 最常用的监控方案 - 每天5分钟玩转 Docker 容器技术(78)

    当 Docker 部署规模逐步变大后,可视化监控容器环境的性能和健康状态将会变得越来越重要. 在本章中,我们将讨论几个目前比较常用的容器监控工具和方案,为大家构建自己的监控系统提供参考. 首先我们会讨 ...

  3. docker stack 部署容器监控方案(cAdvisor、Prometheus、Grafana)

    =============================================== 2018/7/8_第1次修改                       ccb_warlock === ...

  4. Work 4(通知类) (2019.04.25)

  5. centos7下安装docker(17.5docker监控的总结对比)

    到现在为止,我已经学习了docker自带的监控方案:ps/ls/top/stats,以及sysdig,weave scope,cadvisor,prometheus多种监控工具,现在做个总结和比较 部 ...

  6. docker管理监控方案

    docker相关管理可分为四类:docker基础功能.docker监控.docker集群管理和docker系统认证管理.docker管理的基础或信息来源都是docker命令行或docker API. ...

  7. 斌哥的 Docker 进阶指南—监控方案的实现

    过去的一年中,关于 Docker 的话题从未断过,而如今,从尝试 Docker 到最终决定使用 Docker 的转化率依然在逐步升高,关于 Docker 的讨论更是有增无减.另一方面,大家的注意力也渐 ...

  8. 一张表搞懂各种 Docker 监控方案 - 每天5分钟玩转 Docker 容器技术(86)

    前面我们已经介绍了ps/top/stats.Sysdig.Weave Scope.cAdvisor 和 Prometheus 多种容器监控工具和方案,是时候做一个比较了.下面将从五个方面来对比它们之间 ...

  9. 086、一张表搞定各种Docker监控方案(2019-05-08 周三)

    参考https://www.cnblogs.com/CloudMan6/p/7736176.html   前面已经学习了  ps/top/stats.Sysdig.Weave Scope .cAdvi ...

随机推荐

  1. Redis 主从复制原理及雪崩 穿透问题

    定义: Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发工作由VMw ...

  2. Linux学习历程——Centos 7 find 命令

    一.命令介绍 find 命令用于按照指定条件来查找文件. 一些比较常用参数如下表 参数 作用 -name 匹配名称 -perm 匹配权限mode为完全匹配( –mode包含即可) -user 匹配所有 ...

  3. [idea] SpringBoot整合swagger2实现CRUD

    一:创建SpringBoot ,在pom.xml文件中加入jar包 <dependency> <groupId>io.springfox</groupId> < ...

  4. 周一04.2流程控制if……else

    语法一:  if 条件1: 代码1 代码2 例题:如果年龄>20岁,那么:叫阿姨 age=22if age>20: print('阿姨') 语法二: if 条件1: 代码1 代码2else ...

  5. 对const的总结与思考

    今天偶然想起const这一关键字,再加之以前几种const修饰指针方式让我印象深刻(混淆不清),重新回顾了一下,自己对这个关键词也又有了更加深刻的理解,所以总结一下. 一.const的定义 const ...

  6. 使用 canvas 画图时图像文字模糊的解决办法

    最近在使用 canvas 画图的时候,遇到了图像文字模糊的问题,解决思路就是根据分辨率创建不同尺寸的画布.以下是创建高分辨率画布的代码: /** * 创建高分辨率画布 * @param w 画布宽 * ...

  7. win 解压安装mysql步骤

    5  安装成功之后,启动mysql时报错: 系统错误2,找不到指定的文件.原因:有的系统安装过MySQL没有卸载干净,或者系统自带精简版的MySQL导致注册表关于MySQL的配置与实际安装路径不一致. ...

  8. 小项目一---Python日志分析

    日志分析 概述 分析的前提 半结构化数据 文本分析  提取数据(信息提取)  一.空格分隔 with open('xxx.log')as f: for line in f: for field in ...

  9. java篇 之 流程控制语句

    条件判断语句 条件语句: If(boolean类型) {} else {}    (打大括号避免出错) switch (export)语句:export的类型必须是 byte,short,char,i ...

  10. Ubuntu 16.04 安装opencv3.4.5/cuda/caffe并使用jni笔记

    因操作失误,误卸开发机NVIDIA显卡驱动,先更新操作日志如下: 1>NVIDIA驱动重装 1.卸载系统里的Nvidia残余 sudo apt-get purge nvidia* 2.把显卡驱动 ...