nginx-lua-prometheus
nginx-lua-prometheus copied to clipboard
Add variable value instead of prometheus metrics in init_worker_by_lua_block
Hey,
I have this scenario where I am calculating the latency value by subtracting two value and want to expose it as prometheus metrics. Is there any way I can do expose this value? Probably something like this:
http {
map $host $request_time_ms {
default '';
}
log_by_lua '
ngx.var.request_time_ms = $request_time - $upstream_custom_response_time
';
lua_shared_dict prometheus_metrics 10M;
lua_package_path "/path/to/nginx-lua-prometheus/?.lua;;";
init_worker_by_lua_block {
prometheus = require("prometheus").init("prometheus_metrics")
metric_latency = prometheus:histogram(ngx.var.request_time_ms, "HTTP request latency", {"uri", "status"})
}
}