Prometheus 监控redis并预警(redis_exporter+prometheus+grafana)

下载安装

  1. 源码编译安装
git clone https://github.com/oliver006/redis_exporter.git
cd redis_exporter
go build .
./redis_exporter --version
  1. 现在二进制包安装
#下载适合自己系统的安装包
wget https://github.com/oliver006/redis_exporter/releases/download/v1.10.0/redis_exporter-v1.10.0.linux-386.tar.gz
#里面的addr 不要改名字后面grafana 中的json 有引用
tar xf redis_exporter-v1.10.0.linux-386.tar.gz
nohup ./redis_exporter -redis.addr xxx:port -redis.password password &

监控集群时

此方法有问题,弃用

nohup ./redis_exporter  -redis.addr xxx:port,xxx:port,xxx:port -redis.password xxx &

修改Prometheus.yml配置文件

  - job_name: 'redis'
    static_configs:
    - targets: ['localhost:9121']

Prometheus加载配置文件

killall -HUP prometheus

如果用集群模式报错:

redis_exporter_last_scrape_error{err="dial tcp: address xxxx xxxx xxxx: too many colons in address"} 1

采用官方推荐用法

修改Prometheus.yml

  - job_name: 'redis_exporter_targets'
    static_configs:
      - targets:
        - redis://47.104.205.107:7000
        - redis://47.104.205.107:7001
        - redis://47.104.205.107:7002
    metrics_path: /scrape
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: localhost:9121

  ## config for scraping the exporter itself
  - job_name: 'redis_exporter'
    static_configs:
      - targets:
        - localhost:9121

重新启动redis_exporter

nohup ./redis_exporter -redis.password xxxxx  &

查看targets

查看redis集群

查看redis集群状态

然后可以在Grafana中绘制折线图以及监控预警。

# redis   prometheus   grafana  

评论

企鹅群:39438021

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×