mod_prometheus: Invoke stats collection if in 'manual' mode
authorKim Alvefur <zash@zash.se>
Tue, 13 Apr 2021 23:53:53 +0200
changeset 4546 fb4a50bf60f1
parent 4545 140cda94c342
child 4547 9377b5593cc7
mod_prometheus: Invoke stats collection if in 'manual' mode Since 10d13e0554f9 a special value for statistics_interval "manual" exists, where a module is expected to invoke processing in connection to collection of stats. This makes internal collection and exporting to Prometheus happens at the same time with no chance of timers getting out of sync.
mod_prometheus/mod_prometheus.lua
--- a/mod_prometheus/mod_prometheus.lua	Sun Apr 11 21:59:50 2021 +0200
+++ b/mod_prometheus/mod_prometheus.lua	Tue Apr 13 23:53:53 2021 +0200
@@ -11,7 +11,8 @@
 local t_insert = table.insert;
 local t_concat = table.concat;
 local socket = require "socket";
-local get_stats = require "core.statsmanager".get_stats;
+local statsman = require "core.statsmanager";
+local get_stats = statsman.get_stats;
 
 local function escape(text)
 	return text:gsub("\\", "\\\\"):gsub("\"", "\\\""):gsub("\n", "\\n");
@@ -126,6 +127,9 @@
 local function get_metrics(event)
 	local response = event.response;
 	response.headers.content_type = "text/plain; version=0.0.4";
+	if statsman.collect then
+		statsman.collect()
+	end
 
 	local answer = {};
 	for key, fields in pairs(parse_stats()) do