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.16k stars 875 forks source link

Add an option to get the check-keys value from a Redis key #786

Closed AlexisBRENON closed 7 months ago

AlexisBRENON commented 1 year ago

Describe the problem

Hi. I use a scheme where I build multiple queues (redis sorted sets) following the pattern <hour_bucket>:<lang>:queue. As you can guess, hour_bucket ranges from 00 to 23. However the lang value is the iso alpha 3 code of a language (fra, eng, etc.). I would like to track the length of all queues. While I can easily generate the hour_bucket part, it’s more difficult to do it for the lang. Generating it for all defined language would be quiet useless as most of the languages are never used, but I can’t tell before hand which one will be used. Using the check-keys option is not very suitable as I can have a lot of keys in the DB, and so it requires a lot of SCAN calls...

As a workaround, I think about 2 solutions:

  1. Create a queue_sizes hash key with each field containing a single integer telling the size of each queue
  2. Provide one indirection step. I mean, I put in the key queue_keys the comma-separated list of queues to observe, and the exporter read this value to get the list of keys to checks.

What version of redis_exporter are you running? Latest docker image Redis Metrics Exporter v1.50.0 build date: sha1: b5e02003cea4b73054abe29433c264dec16cc1f0 Go: go1.20.3 GOOS: linux GOARCH: arm64

Running the exporter

docker run oliver006/redis_exporter --redis.addr=redis://redis:6379 --check-single-keys=queue_sizes
oliver006 commented 1 year ago

Can you try using a lua script?

AlexisBRENON commented 1 year ago

I suppose that you suggest to use a script as demonstrated for the list size metrics, doesn't you ? However, from the eval documentation:

all names of keys that a script accesses must be explicitly provided as input key arguments

How do you handle that ? Which input key arguments are passed to the script from the redis-exporter ?

ivanovv commented 1 year ago

@AlexisBRENON the file you mentioned has this line

local keysPresent = redis.call("KEYS", "KEYS_PATTERN")

So it looks like that you can ignore that part of eval doc.

At least I tried calling 'KEYS' and it worked.