记录一下使用 Cadvisor+Prometheus+Grafana 监控 docker 的搭建过程。
全部使用 docker 容器搭建,效果还不错。

Cadvisor

1
2
3
4
5
6
7
8
9
docker run    \                                      
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest

Prometheus

编辑 /etc/prometheus/prometheus.yml

1
2
3
4
5
6
7
8
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: 'docker'
static_configs:
- targets: ['192.168.1.152:8080']

启动

1
2
3
4
5
docker run    \ 
-p 9090:9090 -d \
-v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
--name prometheus \
prom/prometheus

启动后访问 http://ip:9090 Status 中的 Targets,确保 job 处于 up 状态。

Grafana

启动

1
2
3
4
docker run    \
--name grafana \
-d -p 3000:3000 \
grafana/grafana

启动后访问http://ip:3000

  • 添加 Data Sources:选择 Prometheus, URL 配置为http://192.168.1.152:9090
  • 导入 dashboard:选择模板https://grafana.com/dashboards/193https://grafana.com/grafana/dashboards/10566。import 后可看到效果。