使用prometheus监控redis

发布时间 2023-07-29 11:33:45作者: 章怀柔

下载redis_exporter插件

官方没提供专门的redis_exporter,github上有人开发了

https://github.com/oliver006/redis_exporter

安装步骤:

git clone https://github.com/oliver006/redis_exporter.git

cd redis_exporter

go build .

./redis_exporter --version

编译时遇到报错

  1. # go build .

  2. go: golang.org/x/sys@v0.0.0-20190405154228-4b34438f7a67: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: connect: connection timed out

可以先设置 GOPROXY 变量

export GOPROXY=https://goproxy.io

go build .

启动redis_exporter

redis_exporter 可以支持监控单实例和多实例。如果监控一个redis 可以使用

nohup ./redis_exporter -redis.addr 127.0.0.1:6379 &

监控多个redis 则需要先启动exporter

nohup ./redis_exporter &

然后在prometheus.yml 的文件中添加

  1. - job_name: 'redis_exporter_targets'

  2. static_configs:

  3. - targets:

  4. - redis://10.9.106.217:6379

  5. - redis://10.9.106.217:6381

  6. metrics_path: /scrape

  7. relabel_configs:

  8. - source_labels: [__address__]

  9. target_label: __param_target

  10. - source_labels: [__param_target]

  11. target_label: instance

  12. - target_label: __address__

  13. replacement: 10.9.11.22:9121

  14.  

  15. ## config for scraping the exporter itself

  16. - job_name: 'redis_exporter'

  17. static_configs:

  18. - targets:

  19. - 10.9.11.22:9121

重新reload配置

sudo curl 'http://localhost:9090/-/reload' -X POST

采集到的redis监控数据

 

配置grafna

  1. 配置prometheus数据源,添加prometheus插件

  2. 下载redis仪表盘模板,选择prometheus数据源,然后上传json文件,下载地址: https://grafana.com/grafana/dashboards/763/revisions

   

 转载自杨奇龙博客