From 19746da12f6193ace11f67afc0ba188121758150 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 6 Apr 2021 23:25:15 +0200 Subject: core.statsmanager: Allow special "manual" value for statistics_interval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When set, no periodic statistics collection is done by core.statsmanager, instead some module is expected to call collect() when it suits. Obviously only one such module should be enabled. Quoth jonas’ > correct way is to scrape the internal sources on each call to /metrics > in the context of Prometheus "manual" as opposed to "automatic", from the point of view of statsmanager. --- core/statsmanager.lua | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'core/statsmanager.lua') diff --git a/core/statsmanager.lua b/core/statsmanager.lua index 1f958194..bca7510f 100644 --- a/core/statsmanager.lua +++ b/core/statsmanager.lua @@ -6,7 +6,7 @@ local fire_event = prosody.events.fire_event; local stats_interval_config = config.get("*", "statistics_interval"); local stats_interval = tonumber(stats_interval_config); -if stats_interval_config and not stats_interval then +if stats_interval_config and not stats_interval and stats_interval_config ~= "manual" then log("error", "Invalid 'statistics_interval' setting, statistics will be disabled"); end @@ -19,6 +19,9 @@ if not stats_provider and stats_interval then elseif stats_provider and not stats_interval then stats_interval = 60; end +if stats_interval_config == "manual" then + stats_interval = nil; +end local builtin_providers = { internal = "util.statistics"; @@ -65,8 +68,7 @@ if stats then return f(name, conf); end - if stats_interval then - log("debug", "Statistics enabled using %s provider, collecting every %d seconds", stats_provider_name, stats_interval); + if stats_interval or stats_interval_config == "manual" then local mark_collection_start = measure("times", "stats.collection"); local mark_processing_start = measure("times", "stats.processing"); @@ -96,9 +98,14 @@ if stats then end return stats_interval; end - timer.add_task(stats_interval, collect); - prosody.events.add_handler("server-started", function () collect() end, -1); - prosody.events.add_handler("server-stopped", function () collect() end, -1); + if stats_interval then + log("debug", "Statistics enabled using %s provider, collecting every %d seconds", stats_provider_name, stats_interval); + timer.add_task(stats_interval, collect); + prosody.events.add_handler("server-started", function () collect() end, -1); + prosody.events.add_handler("server-stopped", function () collect() end, -1); + else + log("debug", "Statistics enabled using %s provider, no scheduled collection", stats_provider_name); + end else log("debug", "Statistics enabled using %s provider, collection is disabled", stats_provider_name); end @@ -107,8 +114,13 @@ else function measure() return measure; end end +local exported_collect = nil; +if stats_interval_config == "manual" then + exported_collect = collect; +end return { + collect = exported_collect; measure = measure; get_stats = function () return latest_stats, changed_stats, stats_extra; -- cgit v1.2.3