oliver006 / redis_exporter

Prometheus Exporter for ValKey & Redis Metrics. Supports ValKey and Redis 2.x, 3.x, 4.x, 5.x, 6.x, and 7.x
https://github.com/oliver006/redis_exporter
MIT License
3.12k stars 876 forks source link

Connection on one instance with Master & Slave Failed #774

Closed imatthew-nq closed 1 year ago

imatthew-nq commented 1 year ago

Describe the problem In a redis cluster built on 5 instances and each instance runs master and slave on different ports and the whole cluster has credential authentication.

172.16.1.21 7000 master
172.16.1.21 7002 slave
172.16.1.22 7000 master
172.16.1.22 7001 slave
172.16.1.23 7000 master
172.16.1.23 7001 slave
172.16.1.24 7000 master
172.16.1.24 7001 slave
172.16.1.25 7000 master
172.16.1.25 7001 slave

Create a redis_exporter.conf file and it contains master & slave IP and PORT + PASSWORD

redis_addr: "redis://<PASSWORD>@IP:7000"
redis_alias: "master"

redis_slave_addr: "redis://<PASSWORD>@IP:7001"
redis_slave_alias: "slave"

namespace: "redis"

When running the below command there would be errors appear:

redis_exporter -config-command redis_exporter.conf 
INFO[0000] Redis Metrics Exporter v1.48.0    build date: 2023-03-03-03:23:47    sha1: 30fba62cc31d80ccb8653ac33965e17c15929a24    Go: go1.20.1    GOOS: linux    GOARCH: amd64 
INFO[0000] Providing metrics at :9121/metrics           
ERRO[0001] Couldn't connect to redis instance (redis://localhost:6379) 
ERRO[0002] Couldn't connect to redis instance (redis://localhost:6379) 

Running the exporter redis_exporter -config-command redis_exporter.conf

There is no redis service running on redis://localhost:6379 and when I pass the config file to redis_exporter it does not work probably.

What version of redis_exporter are you running? [ redis_version] 5.0.7 [redis_exporter ] v1.48.0.linux-amd64

oliver006 commented 1 year ago

-config-command is for changing the name of the CONFIG command, not for proving a config file.

You have to pass the Redis address parameter directly (using -redis.addr et al) and you can't connect to two instances with one exporter, use an exporter for each instance.

imatthew-nq commented 1 year ago

Thank you for your quick answer oliver006 I can connect to two redis instances via two redis_exporter, am I right? And is it possible to change exporter_addr for each instance to scrape with Prometheus? for example in config-file which passes to redis_exporter_1.service to gets master instance metrics use exporter_addr: ":9121" and for the other redis_exporter_2.service use exporter_addr: ":9122" to gets slave instance metrics?

imatthew-nq commented 1 year ago

I got the answer and I wanted to share it with you In one of the instances I created two services and each one of those services contains below contents:

#redis_exporter_master.service and it scraped on port:9121
Description=Redis Exporter Master
After=network.target

[Service]
Type=simple
User=redis
Group=redis
WorkingDirectory=/opt/prometheus/redis_exporter/
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/opt/prometheus/redis_exporter/redis_exporter -redis.addr redis://172.16.1.21:7000 -redis.password-file pass.json

SyslogIdentifier=redis_exporter
Restart=always

[Install]
WantedBy=multi-user.target

For the slave instance on the same server, I created and pass some more parameters on the service section:

#redis_exporter_slave.service and it scraped on port:9122
Description=Redis Exporter Slave
After=network.target

[Service]
Type=simple
User=redis
Group=redis
WorkingDirectory=/opt/prometheus/redis_exporter/
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/opt/prometheus/redis_exporter/redis_exporter -redis.addr redis://172.16.1.21:7001 -redis.password-file pass2.json -web.listen-address :9122

SyslogIdentifier=redis_exporter
Restart=always

[Install]
WantedBy=multi-user.target

pass.json context is:

{
  "redis://172.16.1.21:7000": "[PASSWORD]"
}

pass2.json context is:

{
  "redis://172.16.1.21:7001": "[PASSWORD]"
}

Both Services of redis_exporter work like a charm. Thank you for your help.

oliver006 commented 1 year ago

Good to hear you got it figured out!