diff options
author | Kim Alvefur <zash@zash.se> | 2021-04-06 23:25:15 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-04-06 23:25:15 +0200 |
commit | 19746da12f6193ace11f67afc0ba188121758150 (patch) | |
tree | f65ec65666cf546de620aa43d0ffe085968aae91 | |
parent | 7c5659808a440093dfce526f4f3d6bf1b2681b46 (diff) | |
download | prosody-19746da12f6193ace11f67afc0ba188121758150.tar.gz prosody-19746da12f6193ace11f67afc0ba188121758150.zip |
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.
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | core/statsmanager.lua | 24 |
2 files changed, 19 insertions, 6 deletions
@@ -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; |