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.09k stars 873 forks source link

lua script metric support custom attribute #922

Open kunlun122 opened 1 month ago

kunlun122 commented 1 month ago

Describe the problem Now lua script metric only support one custom attribute named "key", I think custom attribute maybe butter.

What version of redis_exporter are you running? 1.60.0

Running the exporter lua script

local result = {}
local nodes_info = redis.pcall('CLUSTER', 'NODES')

if type(nodes_info) == 'string' then
    for line in string.gmatch(nodes_info, '([^\n]+)') do
        if string.find(line, 'myself') then

            local parts = {}
            local idx = 1
            for part in string.gmatch(line, '([^%s]+)') do
                parts[idx] = part
                idx = idx + 1
            end

            table.insert(result, 'node_info_address='..parts[2])
            table.insert(result, "1")

            break
        end
    end
else
    table.insert(result, 'Error running CLUSTER NODES')
end

return result

Screenshots script metrics

# HELP redis_script_result Result of the collect script evaluation
# TYPE redis_script_result gauge
redis_script_result{filename="/opt/server_info.lua"} 1
# HELP redis_script_values Values returned by the collect script
# TYPE redis_script_values gauge
redis_script_values{filename="/opt/server_info.lua",key="node_info_address=10.42.2.120:6379@16379"} 1

image

Additional context hope we can custom the redis_script_values attributes

redis_script_values{filename="/opt/server_info.lua", node_info_address="10.42.2.120:6379@16379"} 1

oliver006 commented 1 month ago

🧈

I like the idea, adding this makes sense. I currently do not have the time to implement this but a PR for this feature would be great and I can help with reviewing this.

kunlun122 commented 1 month ago

But I am a Java developer ...

wilkice commented 1 month ago

Prometheus currently seems don't support dynamic label for metrics. So this is hard to implement now.