一、Docker 查看信息命令
原生命令
docker stats命令的结果
![](https://files.mdnice.com/user/27110/c8c5b570-b58a-44c0-b794-e0e40bcd8684.png)
存在问题
通过docker stats命令可以很方便的看到当前宿主机上所有容器的CPU,内存以及网络流量等数据,但是,docker stats统计结果只能是当前宿主机的全部容器,数据资料是实时的,没有地方存储、没有健康指标过线预警等功能
二、CAdvisor+InfluxDB+Granfana
容器监控3剑客
CAdvisor监控收集+InfluxDB存储数据+Granfana展示图表
![](https://files.mdnice.com/user/27110/bdcf0d41-b8a3-463d-9846-894ea4a893ad.png)
CAdvisor
![](https://files.mdnice.com/user/27110/d8d93d98-f8ce-47a6-b791-aa4d9ccf8771.png)
InfluxDB
![](https://files.mdnice.com/user/27110/5c2677c5-5317-4b98-b74b-16dce1f898f5.png)
Granfana
![](https://files.mdnice.com/user/27110/9ced8514-c185-4b3f-b1da-5cf267c173e0.png)
小结
![](https://files.mdnice.com/user/27110/772d3097-d0a5-4177-84df-206ac4dc5491.png)
三、compose容器编排
1、新建目录
![](https://files.mdnice.com/user/27110/22347d1e-1b77-4160-8a6f-89fb3d7e6213.png)
2、新建3件套组合的 docker-compose.yml
version: '3.1'
volumes:
grafana_data: {}
services:
influxdb:
image: tutum/influxdb:0.9
restart: always
environment:
- PRE_CREATE_DB=cadvisor
ports:
- "8083:8083"
- "8086:8086"
volumes:
- ./data/influxdb:/data
cadvisor:
image: google/cadvisor
links:
- influxdb:influxsrv
command: -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086
restart: always
ports:
- "8080:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
grafana:
user: "104"
image: grafana/grafana
user: "104"
restart: always
links:
- influxdb:influxsrv
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
environment:
- HTTP_USER=admin
- HTTP_PASS=admin
- INFLUXDB_HOST=influxsrv
- INFLUXDB_PORT=8086
- INFLUXDB_NAME=cadvisor
- INFLUXDB_USER=root
- INFLUXDB_PASS=root
3、启动docker-compose文件
docker-compose up
![](https://files.mdnice.com/user/27110/6bca5042-2d0e-48ba-b248-844aece2c100.png)
![](https://files.mdnice.com/user/27110/627badbf-1f7e-46e0-ab1f-07784dc6da6e.png)
4、查看三个服务容器是否启动
![](https://files.mdnice.com/user/27110/118fa232-bc01-4ebe-9acb-a6584fdec173.png)
四、测试
1、浏览cAdvisor收集服务,http://ip:8080/
第一次访问慢,请稍等
cadvisor也有基础的图形展现功能,这里主要用它来作数据采集
2、浏览influxdb存储服务,http://ip:8083/
3、浏览grafana展现服务,http://ip:3000
ip+3000端口的方式访问,默认帐户密码(admin/admin)
配置步骤:
(1)配置数据源
![](https://files.mdnice.com/user/27110/7d31d490-a5ed-4b7b-9568-e1a478381af7.png)
(2)选择influxdb数据源
![](https://files.mdnice.com/user/27110/fbf509e3-ea75-4ba9-bf40-858041d71268.png)
(3)配置细节
![](https://files.mdnice.com/user/27110/d41e4ac6-afd5-4ec3-a1fa-b45ecab2b3b2.png)
![](https://files.mdnice.com/user/27110/ccf99de4-b615-4227-a244-371b8c0744e6.png)
![](https://files.mdnice.com/user/27110/e9c9dd79-a7e8-41ae-9b5a-a3dd59c0255d.png)
(4)配置面板panel
![](https://files.mdnice.com/user/27110/4c4a0b1c-8938-48e4-b247-f455f9c99c0b.png)
![](https://files.mdnice.com/user/27110/6b3e6fc0-2ca6-4ca3-b03e-139f2c9b0735.png)
![](https://files.mdnice.com/user/27110/e01057f0-3e49-4aa3-849e-e6a5095241ba.png)
![](https://files.mdnice.com/user/27110/c7a0f33b-1117-4ab4-8b81-48aa350ed628.png)
![](https://files.mdnice.com/user/27110/fc39acb8-1092-4fc2-bd62-47e5916f15c0.png)
![](https://files.mdnice.com/user/27110/fa73258d-8b22-49a1-b9ba-16b3fdaf0b77.png)
到这里cAdvisor+InfluxDB+Grafana容器监控系统就部署完成了