监控规划图
使用 Docker 创建两台 Redis
- docker run -d --name redis1 Redis
- docker run -d --name redis2 Redis
查看 Redis 的部署地址
docker inspect (docker ps -a | grep Redis | awk '{print $1}') | grep IPAddress
部署 redis_exporter 收集 Redis 数据
- docker run -d --name redis_exporter_1 -p 9121:9121 oliver006/redis_exporter --Redis.addr=172.17.0.2:6379
- docker run -d --name redis_exporter_2 -p 9122:9121 oliver006/redis_exporter --Redis.addr=172.17.0.3:6379
添加 prometheus 配置文件
- global:
- scrape_interval: 15s
- evaluation_interval: 15s
- # Attach these labels to any time series or alerts when communicating with
- # external systems (federation, remote storage, Alertmanager).
- external_labels:
- monitor: "prometheus-stack-monitor"
- # Load and evaluate rules in this file every 'evaluation_interval' seconds.
- #rule_files:
- # - "first.rules"
- # - "second.rules"
- scrape_configs:
- # scrape Prometheus itself
- - job_name: prometheus
- scrape_interval: 10s
- scrape_timeout: 5s
- static_configs:
- - targets: ["localhost:9090"]
- # scrape Redis Enterprise
- - job_name: Redis-enterprise
- scrape_interval: 3s
- scrape_timeout: 3s
- static_configs:
- - targets: ['172.17.0.4:9121','172.17.0.7:9121']
targets 中为 redis_exporter 的地址和端口号, 多个逗号分隔
部署 prometheus
docker run -d --name prome -p 9090:9090 -v /prometheus/prometheus.YAML:/etc/prometheus/prometheus.YAML prom/prometheus
prometheus 配置文件需要使用绝对位置
部署 grafana
docker run -d --name=grafana -p 3000:3000 grafana/grafana
添加 prometheus 数据源
下载 Redis 模板 且导入到 grafana
效果图
来源: https://www.cnblogs.com/alin-qu/p/11746128.html