comparison mod_measure_modules/mod_measure_modules.lua @ 5668:ecfd7aece33b

mod_measure_modules: Report module statuses via OpenMetrics Someone in the chat asked about a health check endpoint, which reminded me of mod_http_status, which provides access to module statuses with full details. After that, this idea came about, which seems natural. As noted in the README, it could be used to monitor that critical modules are in fact loaded correctly. As more modules use the status API, the more useful this module and mod_http_status becomes.
author Kim Alvefur <zash@zash.se>
date Fri, 06 Oct 2023 18:34:39 +0200
parents
children
comparison
equal deleted inserted replaced
5667:9bcd257dea4e 5668:ecfd7aece33b
1 module:set_global();
2
3 local mm = require "core.modulemanager";
4 local sm = require "core.statsmanager";
5
6 local measure_status = sm.metric("gauge", "prosody_module_status", "", "Prosody module status", { "host"; "module" });
7
8 local status_priorities = { error = 3; warn = 2; info = 1; core = 0 };
9
10 function module.add_host(module)
11 local measure = measure_status:with_partial_label(module.host);
12
13 if module.global then
14 measure = measure_status:with_partial_label(":global");
15 end
16
17 -- Already loaded modules
18 local modules = mm.get_modules(module.host);
19 for name, mod in pairs(modules) do
20 measure:with_labels(name):set(status_priorities[mod.module.status_type] or 0);
21 end
22
23 -- TODO hook module load and unload
24
25 -- Future changes
26 module:hook("module-status/updated", function(event)
27 local mod = mm.get_module(event.name);
28 measure:with_labels(event.name):set(status_priorities[mod and mod.module.status_type] or 0);
29 end);
30
31 end
32
33 module:add_host(); -- Initialize global context