Annotate

core/statsmanager.lua @ 11515:10d13e0554f9

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.
author Kim Alvefur <zash@zash.se>
date Tue, 06 Apr 2021 23:25:15 +0200
parent 11506:9a3ebdd65f9c
child 11523:5f15ab7c6ae5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local config = require "core.configmanager";
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local log = require "util.logger".init("stats");
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local timer = require "util.timer";
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local fire_event = prosody.events.fire_event;
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
7 local stats_interval_config = config.get("*", "statistics_interval");
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
8 local stats_interval = tonumber(stats_interval_config);
11515
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
9 if stats_interval_config and not stats_interval and stats_interval_config ~= "manual" then
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 log("error", "Invalid 'statistics_interval' setting, statistics will be disabled");
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 end
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
13 local stats_provider_name;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
14 local stats_provider_config = config.get("*", "statistics");
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
15 local stats_provider = stats_provider_config;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
16
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
17 if not stats_provider and stats_interval then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
18 stats_provider = "internal";
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
19 elseif stats_provider and not stats_interval then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
20 stats_interval = 60;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
21 end
11515
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
22 if stats_interval_config == "manual" then
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
23 stats_interval = nil;
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
24 end
7521
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
25
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
26 local builtin_providers = {
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
27 internal = "util.statistics";
7522
ebf2e77ac8a7 statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents: 7521
diff changeset
28 statsd = "util.statsd";
7521
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
29 };
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
30
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
31
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
32 local stats, stats_err = false, nil;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
33
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
34 if stats_provider then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
35 if stats_provider:sub(1,1) == ":" then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
36 stats_provider = stats_provider:sub(2);
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
37 stats_provider_name = "external "..stats_provider;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
38 elseif stats_provider then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
39 stats_provider_name = "built-in "..stats_provider;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
40 stats_provider = builtin_providers[stats_provider];
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
41 if not stats_provider then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
42 log("error", "Unrecognized statistics provider '%s', statistics will be disabled", stats_provider_config);
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
43 end
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
44 end
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
45
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
46 local have_stats_provider, stats_lib = pcall(require, stats_provider);
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
47 if not have_stats_provider then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
48 stats, stats_err = nil, stats_lib;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
49 else
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
50 local stats_config = config.get("*", "statistics_config");
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
51 stats, stats_err = stats_lib.new(stats_config);
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
52 stats_provider_name = stats_lib._NAME or stats_provider_name;
7521
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
53 end
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
54 end
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
55
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
56 if stats == nil then
7521
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
57 log("error", "Error loading statistics provider '%s': %s", stats_provider, stats_err);
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
58 end
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
59
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 local measure, collect;
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 local latest_stats = {};
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 local changed_stats = {};
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 local stats_extra = {};
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64
7521
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
65 if stats then
10884
6992c4be1a19 core.statsmanager: Allow passing a config table trough measure
Kim Alvefur <zash@zash.se>
parents: 10539
diff changeset
66 function measure(type, name, conf)
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 local f = assert(stats[type], "unknown stat type: "..type);
10884
6992c4be1a19 core.statsmanager: Allow passing a config table trough measure
Kim Alvefur <zash@zash.se>
parents: 10539
diff changeset
68 return f(name, conf);
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 end
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
70
11515
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
71 if stats_interval or stats_interval_config == "manual" then
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
72
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
73 local mark_collection_start = measure("times", "stats.collection");
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
74 local mark_processing_start = measure("times", "stats.processing");
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
75
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
76 function collect()
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
77 local mark_collection_done = mark_collection_start();
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
78 fire_event("stats-update");
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
79 mark_collection_done();
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
80
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
81 if stats.get_stats then
11506
9a3ebdd65f9c core.statsmanager: Cover util.statistics work in processing measurement
Kim Alvefur <zash@zash.se>
parents: 10884
diff changeset
82 local mark_processing_done = mark_processing_start();
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
83 changed_stats, stats_extra = {}, {};
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
84 for stat_name, getter in pairs(stats.get_stats()) do
10539
25f80afb1631 core.statsmanager: Ignore unused variable [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9804
diff changeset
85 -- luacheck: ignore 211/type
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
86 local type, value, extra = getter();
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
87 local old_value = latest_stats[stat_name];
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
88 latest_stats[stat_name] = value;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
89 if value ~= old_value then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
90 changed_stats[stat_name] = value;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
91 end
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
92 if extra then
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
93 stats_extra[stat_name] = extra;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
94 end
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
95 end
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
96 fire_event("stats-updated", { stats = latest_stats, changed_stats = changed_stats, stats_extra = stats_extra });
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
97 mark_processing_done();
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
98 end
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
99 return stats_interval;
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
100 end
11515
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
101 if stats_interval then
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
102 log("debug", "Statistics enabled using %s provider, collecting every %d seconds", stats_provider_name, stats_interval);
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
103 timer.add_task(stats_interval, collect);
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
104 prosody.events.add_handler("server-started", function () collect() end, -1);
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
105 prosody.events.add_handler("server-stopped", function () collect() end, -1);
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
106 else
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
107 log("debug", "Statistics enabled using %s provider, no scheduled collection", stats_provider_name);
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
108 end
7533
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
109 else
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
110 log("debug", "Statistics enabled using %s provider, collection is disabled", stats_provider_name);
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
111 end
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
112 else
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
113 log("debug", "Statistics disabled");
4ef37ac69562 statsmanager: Refactor to simplify logic. Notably renames 'statistics_provider' to 'statistics', and external libs now just begin with ':'
Matthew Wild <mwild1@gmail.com>
parents: 7524
diff changeset
114 function measure() return measure; end
7521
1c8b63fe6472 statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents: 6910
diff changeset
115 end
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116
11515
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
117 local exported_collect = nil;
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
118 if stats_interval_config == "manual" then
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
119 exported_collect = collect;
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
120 end
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 return {
11515
10d13e0554f9 core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents: 11506
diff changeset
123 collect = exported_collect;
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 measure = measure;
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 get_stats = function ()
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 return latest_stats, changed_stats, stats_extra;
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 end;
6910
82765a4ec799 statsmanager: Add get() method
Matthew Wild <mwild1@gmail.com>
parents: 6582
diff changeset
128 get = function (name)
82765a4ec799 statsmanager: Add get() method
Matthew Wild <mwild1@gmail.com>
parents: 6582
diff changeset
129 return latest_stats[name], stats_extra[name];
82765a4ec799 statsmanager: Add get() method
Matthew Wild <mwild1@gmail.com>
parents: 6582
diff changeset
130 end;
6554
6c22bec3e8d0 statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 };