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. --- CHANGES | 1 + core/statsmanager.lua | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index f91e8e44..64df54ff 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ TRUNK - util.error for encapsulating errors - MUC: support for XEP-0421 occupant identifiers - mod_http_file_share: File sharing via HTTP (XEP-0363) +- statistics scheduling can be done by plugin 0.11.0 ====== 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