我们需要对prometheus的数据目录跟配置文件目录做持久化并且设置数据删除时间90天,至于数据目录挂在可以提前copy出来一份
docker run -d --name=prometheus -v /opt/prome/conf/prometheus:/etc/prometheus -v /opt/prome/data/prometheus:/prometheus -p 9090:9090 prom/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles --storage.tsdb.retention=90d --web.enable-lifecycle
--web.enable-lifecycle
开启api 是为了让我们通过api来做热更新配置
curl -X POST http://IP/-/reload
项目github地址https://github.com/oliver006/redis_exporter/releases
注意这里启动redisexporter的时候我们只需要链接一个redis 如果redis是集群规模只需要链接一个哦,其他的我们在prometheus上面配置
wget https://github.com/oliver006/redis_exporter/releases/download/v1.13.1/redis_exporter-v1.13.1.linux-amd64.tar.gz
tar xf redis_exporter-v1.13.1.linux-amd64.tar.gz
cd redis_exporter-v1.13.1.linux-amd64.tar.gz
nohup ./redis_exporter -redis.addr xxx -redis.password xxxx &
修改prometheus.yml
- job_name: 'xxx'
static_configs:
- targets:
- redis://xxxx
- redis://xxxx
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: xxxx:9121
- job_name: 'xxx_exporter'
static_configs:
- targets:
- xxx:9121
并重启prometheus
grafana的模版可以参考https://github.com/oliver006/redis_exporter/blob/master/contrib/grafana_prometheus_redis_dashboard.json