C:CAdvisor,监控收集,默认存储最近2分钟的数据。为了持久化数据使用InflusDB
docker stats统计结果只能是当前宿主机的全部容器,数据资料是实时的,没有地方存储,没有健康指标过线预警等。
mkdir cig
cd cig
vim docker-compose.yml
docker-compose.yml
version: '3'
volumes:
grafana_data: {}
services:
influxdb:
image: tutum/influxdb:0.9
restart: always
ports:
- 8086:8086
- 8083:8083
volumes:
- ./data/influxdb:/data
environment:
- PRE_CREATE_DB=cadvisor
cadvisor:
image: google/cadvisor:latest
restart: always
links:
- influxdb:infuxsrv
command: -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=infuxsrv:8086
ports:
- 8080:8080
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
grafana:
image: grafana/grafana:latest
restart: always
links:
- influxdb:infuxsrv
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
#检查yml文件格式是否有问题,无输出无问题
docker-compose config -q
docker-compose up -d
访问地址:
cadvisor:ip:8080,第一次访问较慢
http://localhost:8080
influxdb:ip:8083
http://localhost:8083/
grafana:ip:3000