Commit 34878d5e authored by Marek Vavruša's avatar Marek Vavruša Committed by Grigorii Demidov

http/prometheus: allow finalization of metrics table

This allows other modules to add or modify custom metrics or labels.
parent 9107aa1d
......@@ -120,6 +120,19 @@ You can namespace the metrics in configuration, using `http.prometheus.namespace
-- Set Prometheus namespace
http.prometheus.namespace = 'resolver_'
You can also add custom metrics or rewrite existing metrics before they are returned to Prometheus client.
.. code-block:: lua
http = {
host = 'localhost',
}
-- Add an arbitrary metric to Prometheus
http.prometheus.finalize = function (metrics)
table.insert(metrics, 'build_info{version="1.2.3"} 1')
end
Tracing requests
^^^^^^^^^^^^^^^^
......
-- Module implementation
local M = {
namespace = '',
finalize = function (_ --[[metrics]]) end,
}
local snapshots, snapshots_count = {}, 120
......@@ -150,6 +151,10 @@ local function serve_prometheus()
end
table.insert(render, string.format('%slatency_count %f', M.namespace, count))
table.insert(render, string.format('%slatency_sum %f', M.namespace, sum))
-- Finalize metrics table before rendering
if type(M.finalize) == 'function' then
M.finalize(render)
end
return table.concat(render, '\n') .. '\n'
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment