- 系统初始化docker环境
- 安装prometheus
#https://prometheus.io/docs/prometheus/latest/installation/
#下载镜像
docker pull prom/prometheus
docker run -d -p 9090:9090 prom/prometheus
#复制一份配置文件到tmp下
docker cp c491:/etc/prometheus/prometheus.yml /tmp
docker rm -f c491
#启动
docker run -d -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
#持久化到存储
#docker run -p 9090:9090 -v /prometheus-data \
prom/prometheus --config.file=/prometheus-data/prometheus.yml
#测试 status targets 查看状态
http://192.168.10.243:9090
#https://github.com/google/cadvisor
sudo docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest
#查看页面和数据采集
http://192.168.10.243:8080/containers/
http://192.168.10.243:8080/metrics
#https://grafana.com/grafana/download?platform=docker
docker run -d --name=grafana -p 3000:3000 grafana/grafana
#登陆 admin admin
http://192.168.10.243:3000/login
#首次登陆需要修改密码
grafana登陆后首先添加 数据源
Add data source
选中 prometheus
http url 中添加prometheus的地址 http://192.168.10.243:9090
#修改prometheus收集cadvisor数据
#修改/tmp/prometheus.yml 最后添加docker job
- job_name: 'docker'
static_configs:
- targets: ['192.168.10.243:8080']
#修改后重启prometheus服务生效配置 如果配置错误无法重启成功 docker logs 查看原因
docker ps | grep pro
docker restart 74bbf2738906
#测试prometheus服务是否收集到数据有container说明数据已经收集

配置grafana可视化展示收集的图表
+ -- dashboard --左上 new dashboard --import dashboard+ 193 (模板ID 可以在官网查询)+Options prometheus 选中添加的prometheus名称
