comparison mod_prometheus/mod_prometheus.lua @ 4542:fb4a50bf60f1

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.
author Kim Alvefur <zash@zash.se>
date Tue, 13 Apr 2021 23:53:53 +0200
parents 343dc9dd70dd
children 64fa2dd34d43
comparison
equal deleted inserted replaced
4541:140cda94c342 4542:fb4a50bf60f1
9 9
10 local tostring = tostring; 10 local tostring = tostring;
11 local t_insert = table.insert; 11 local t_insert = table.insert;
12 local t_concat = table.concat; 12 local t_concat = table.concat;
13 local socket = require "socket"; 13 local socket = require "socket";
14 local get_stats = require "core.statsmanager".get_stats; 14 local statsman = require "core.statsmanager";
15 local get_stats = statsman.get_stats;
15 16
16 local function escape(text) 17 local function escape(text)
17 return text:gsub("\\", "\\\\"):gsub("\"", "\\\""):gsub("\n", "\\n"); 18 return text:gsub("\\", "\\\\"):gsub("\"", "\\\""):gsub("\n", "\\n");
18 end 19 end
19 20
124 end 125 end
125 126
126 local function get_metrics(event) 127 local function get_metrics(event)
127 local response = event.response; 128 local response = event.response;
128 response.headers.content_type = "text/plain; version=0.0.4"; 129 response.headers.content_type = "text/plain; version=0.0.4";
130 if statsman.collect then
131 statsman.collect()
132 end
129 133
130 local answer = {}; 134 local answer = {};
131 for key, fields in pairs(parse_stats()) do 135 for key, fields in pairs(parse_stats()) do
132 t_insert(answer, repr_help(key, "TODO: add a description here.")); 136 t_insert(answer, repr_help(key, "TODO: add a description here."));
133 t_insert(answer, repr_type(key, fields[1].typ)); 137 t_insert(answer, repr_type(key, fields[1].typ));