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.04k stars 860 forks source link

redis_connected_clients_details don't show user info #775

Closed Pablitoeche closed 1 year ago

Pablitoeche commented 1 year ago

Describe the problem redis_connected_clients_details don't show user info from redis 6.

What version of redis_exporter are you running? [ ] 1.46.0

Running the exporter /opt/prometheus-exporters/bin/redis_exporter \ --web.listen-address=127.0.0.1:9121 \ --redis.addr=redis://my.server.local:6379 \ --export-client-list=true \ redis.user=user_mon \ redis.password="###########################"

Additional context Is it possible to add user flag from client list for redis 6? by example, this line: id=120085469 addr=IP:PORT laddr=IP:PORT fd=142 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 argv-mem=0 obl=0 oll=0 omem=0 tot-mem=20512 events=r cmd=set user=test redir=-1 redis exporter metric: redis_connected_clients_details{cmd="set",created_at="1678277183",db="0",flags="N",host="IP",idle_since="1678277183",name="",omem="0"} 1

oliver006 commented 1 year ago

That should totally be doable! https://redis.io/commands/client-list/ shows that the user name is available so adding this should be simple.

I don't have a ton of time right now to add this myself but if you submit a PR I'd be happy to review it.

Pablitoeche commented 1 year ago

Do you think that a control of redis version is neccessary? as the comment in doc https://redis.io/commands/client-list/

Starting with Redis version 6.0.0: Added user field.

oliver006 commented 1 year ago

I think it could be as simple as "if user field is present, add it to the labels", no need for an explicit version check (I don't think any part of the redis_exporter currently checks for a particular redis version)

misTrasteos commented 1 year ago

List of labels for _redis_connected_clientsdetails seems to be statically defined in exporter.go.

connectedClientsLabels := []string{"name", "created_at", "idle_since", "flags", "db", "omem", "cmd", "host"}
if e.options.ExportClientsInclPort {
     connectedClientsLabels = append(connectedClientsLabels, "port")
}

I believe that piece of code is executed during startup, even before we may know there is a user or not. So if a label user is added to that array and there is no user (for instance in a redis v5), label user will be an empty string

redis_connected_clients_details{cmd="client",created_at="1678290637",db="0",flags="N",host="172.17.0.1",idle_since="1678290637",name="redis_exporter",omem="0",user=""} 1

Will this behavior be OK? Or there should be some logic to avoid these emptiness? I am also thinking about breaking promqls

oliver006 commented 1 year ago

Ah, I see. That makes it a bit bigger change as you'd have to create the gauge when you submit the metrics (and then you can create the labels after you got the response from Redis).

oliver006 commented 1 year ago

Closed by #776