# HG changeset patch # User Kim Alvefur # Date 1617744315 -7200 # Node ID 10d13e0554f91c6f8cf237e55ab315d7878251ad # Parent 11186af62c8753581bca1cbe020d53c64f38e159 core.statsmanager: Allow special "manual" value for statistics_interval 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. diff -r 11186af62c87 -r 10d13e0554f9 CHANGES --- a/CHANGES Sat Apr 10 16:45:44 2021 +0200 +++ b/CHANGES Tue Apr 06 23:25:15 2021 +0200 @@ -21,6 +21,7 @@ - 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 -r 11186af62c87 -r 10d13e0554f9 core/statsmanager.lua --- a/core/statsmanager.lua Sat Apr 10 16:45:44 2021 +0200 +++ b/core/statsmanager.lua Tue Apr 06 23:25:15 2021 +0200 @@ -6,7 +6,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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;