File: sample_collect_script.lua

package info (click to toggle)
prometheus-redis-exporter 1.69.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 768 kB
  • sloc: makefile: 121; sh: 92
file content (21 lines) | stat: -rw-r--r-- 651 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- Example collect script for -script option
-- This returns a Lua table with alternating keys and values.
-- Both keys and values must be strings, similar to a HGETALL result.
-- More info about Redis Lua scripting: https://redis.io/commands/eval

local result = {}

-- Add all keys and values from some hash in db 5
redis.call("SELECT", 5)
local r = redis.call("HGETALL", "some-hash-with-stats")
if r ~= nil then
    for _,v in ipairs(r) do
        table.insert(result, v) -- alternating keys and values
    end
end

-- Set foo to 42
table.insert(result, "foo")
table.insert(result, "42") -- note the string, use tostring() if needed

return result