1 监控解决方案
cadvisor+influxdb+grafana
cAdvisor:Google开源的工具,用于监控Docker主机和容器系统资源,通过图形页面实时显示数据,但不存储;它通过宿主机/proc、/sys、/var/lib/docker等目录下文件获取宿主机和容器运行信息。
InfluxDB:是一个分布式的时间序列数据库,用来存储cAdvisor收集的系统资源数据。
Grafana:可视化展示平台,可做仪表盘,并图表页面操作很方面,数据源支持zabbix、Graphite、InfluxDB、OpenTSDB、Elasticsearch等
它们之间关系:
cAdvisor容器数据采集->InfluxDB容器数据存储->Grafana可视化展示
2 下载docker镜像
2.1 下载influxdb镜像
docker pull tutum/influxdb
输出如下:
Using default tag: latest latest: Pulling from tutum/influxdb a3ed95caeb02: Pull complete 23efb549476f: Pull complete aa2f8df21433: Pull complete ef072d3c9b41: Pull complete c9f371853f28: Pull complete a248b0871c3c: Pull complete 749db6d368d0: Pull complete db2492acfcc3: Pull complete b7e7d2e12d53: Pull complete 4272a53eef10: Pull complete 9b2fefdb5321: Pull complete Digest: sha256:5b7c5e318303ad059f3d1a73d084c12cb39ae4f35f7391b79b0ff2c0ba45304b Status: Downloaded newer image for tutum/influxdb:latest
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE tutum/influxdb latest c061e5808198 2 years ago 290MB
2.2 下载cadvisor镜像
$ docker pull google/cadvisor:latest latest: Pulling from google/cadvisor ff3a5c916c92: Pull complete 44a45bb65cdf: Pull complete 0bbe1a2fe2a6: Pull complete Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04 Status: Downloaded newer image for google/cadvisor:latest
镜像信息如下:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE google/cadvisor latest eb1210707573 4 months ago 69.6MB
2.3 下载grafana镜像
$ docker pull grafana/grafana:latest latest: Pulling from grafana/grafana f7e2b70d04ae: Pull complete a0d6f8d6b78d: Pull complete f6dfdd9a4cc9: Pull complete a47b02586edb: Pull complete ac3d2f7cc2e4: Pull complete 857ef2887ebc: Pull complete Digest: sha256:e3796f399ae4f3f85e21807f88675d8ce2221b6011d3c3dd4e7eebce883f157b Status: Downloaded newer image for grafana/grafana:latest
镜像信息如下:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE grafana/grafana latest d20d0cdfb55e 11 days ago 241MB
3. 启动监控
3.1 启动influxdb容器
$docker run -d -p 8083:8083 -p 8086:8086 --name influxdb tutum/influxdb eeb5f0a22e4c75b779be62161ce58055b9e6f497f144cb509a96b6e1735b9786
启动后信息如下:
$docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eeb5f0a22e4c tutum/influxdb "/run.sh" 50 seconds ago Up 48 seconds 0.0.0.0:8083->8083/tcp, 0.0.0.0:8086->8086/tcp influxdb
3.2 启动cadvisor容器
$docker run -d --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --link influxdb:influxdb -p 8081:8080 --name=cadvisor google/cadvisor:latest -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxdb:8086
3.3 启动grafana容器
$docker run -d -p 3000:3000 -e INFLUXDB_HOST=influxdb -e INFLUXDB_PORT=8086 -e INFLUXDB_NAME=cadvisor -e INFLUXDB_USER=cadvisor -e INFLUXDB_PASS=cadvisor --link influxdb:influxsrv --name grafana grafana/grafana