cAdvisor:Google开源的工具,用于监控Docker主机和容器系统资源,通过图形页面实时显示数据,但不存储;它通过宿主机/proc、/sys、/var/lib/docker等目录下文件获取宿主机和容器运行信息
InfluxDB:是一个分布式的时间序列数据库,用来存储cAdvisor收集的系统资源数据。
Grafana:可视化展示平台,可做仪表盘,并图表页面操作很方便,数据源支持zabbix、Graphite、InfluxDB、OpenTSDB、Elasticsearch等
它们之间关系:
cAdvisor容器数据采集—–> InfluxDB容器数据存储—–>Grafana可视化展示
部署InfluxDB
[root@docker-master ~]# docker run -itd -p8083:8083 --name influxdb tutum/influxdb Unable to find image 'tutum/influxdb:latest' locally 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:2772d80e80284b801c6ef255f7e185dd5290757f0f031d77762390dd4df2a9a3 Status: Downloaded newer image for tutum/influxdb:latest docker: Error response from daemon: mkdir /var/lib/docker/overlay/6d0d06de343d70cdd581480780933d4c05904bce9cf381efc1ac630f28acd083-init/merged/dev/shm: invalid argument.
在docker run的时候报了一个错, mkdir /var/lib/docker/overlay/6d0d06de343d70cdd581480780933d4c05904bce9cf381efc1ac630f28acd083-init/merged/dev/shm: invalid argument
解决方法:
[root@docker-master ~]# vim /etc/docker/daemon.json { "storage-driver": "devicemapper" } [root@docker-master ~]# docker run -idt -p 8083:8083 --name influxdb tutum/influxdb Unable to find image 'tutum/influxdb:latest' locally 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:2772d80e80284b801c6ef255f7e185dd5290757f0f031d77762390dd4df2a9a3
创建数据库用来存放cadvisor采集的数据,再创建数据库用户供grafana连接
create database "cadvisor"
查看数据库可以发现数据库已经创建成功了。
# 创建用户
create user "cadvisor" with password 'cadvisor'
OK,数据库用户也已经创建成功。
show users
部署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 Unable to find image 'google/cadvisor:latest' locally latest: Pulling from google/cadvisor ab7e51e37a18: Pull complete a2dc2f1bce51: Pull complete 3b017de60d4f: Pull complete Digest: sha256:9e347affc725efd3bfe95aa69362cf833aa810f84e6cb9eed1cb65c35216632a Status: Downloaded newer image for google/cadvisor:latest c4b2aa505f02e01f61a704dfeac9574ca9d36897896bda9be5c8d688d9ed441f
部署Granfana
docker run -d \ -p 3000:3000 \ -e INFLUXDB_HOST=localhost \ -e INFLUXDB_PORT=8086 \ -e INFLUXDB_NAME=cadvisor \ -e INFLUXDB_USER=cadvisor \ -e INFLUXDB_PASS=cadvisor \ --link influxdb:influxsrv \ --name grafana \ grafana/grafana Unable to find image 'grafana/grafana:latest' locally latest: Pulling from grafana/grafana a5a6f2f73cd8: Pull complete 08e6195c0f29: Pull complete b7bd3a2a524c: Pull complete d3421658103b: Pull complete cd7c84229877: Pull complete 49917e11f039: Pull complete Digest: sha256:b9a31857e86e9cf43552605bd7f3c990c123f8792ab6bea8f499db1a1bdb7d53 Status: Downloaded newer image for grafana/grafana:latest 65e7390c90d8595495a776a66a03df77e474a4fa69d9d248f71236c5b62a580b
访问http://IP:3000 默认用户:admin 密码:admin
添加数据源Add Type里面选择InfluxDB ,最后选择Save&Test 保存测试。
URL填写:http://influxdb:8086 数据库用户及密码填写:cadvisor
在grafana上绘制图表即可展现相关数据