Mercurial > prosody-hg
annotate core/statsmanager.lua @ 11148:1dc49accb58e
core.moduleapi: Return resource path from module:get_directory() (API BC)
:get_directory has so far returned the base directory of the current
module source code. This has worked well so far to load resources which
tend to be included in the same directory, but with the plugin installer
using LuaRocks, extra resources (e.g. templates and other assets) these
are saved in a completely different directory.
In be73df6765b9 core.modulemanager gained some code for finding that
directory and saving it in module.resource_path but now the question is
how this should be reflected in the API.
A survey of community modules suggest the vast majority use the
:get_directory method for locating templates and other assets, rather
than the code (which would use module:require instead).
Therefore this commit changes :get_directory to return the resource_path
when available. This should work for most modules.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 09 Oct 2020 16:37:15 +0200 |
| parents | 6992c4be1a19 |
| children | 9a3ebdd65f9c |
| 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); |
|
7664
4f145a9f1477
core.statsmanager: Use correct variable for config validation [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7533
diff
changeset
|
9 if stats_interval_config and not stats_interval 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 |
|
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
|
22 |
|
1c8b63fe6472
statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents:
6910
diff
changeset
|
23 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
|
24 internal = "util.statistics"; |
|
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
7521
diff
changeset
|
25 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
|
26 }; |
|
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 |
|
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
|
28 |
|
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
|
29 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
|
30 |
|
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 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 |
|
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 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
|
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
|
53 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
|
54 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
|
55 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
|
56 |
|
6554
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 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
|
61 |
|
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
|
62 if stats then |
|
10884
6992c4be1a19
core.statsmanager: Allow passing a config table trough measure
Kim Alvefur <zash@zash.se>
parents:
10539
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
|
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
|
68 if 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
|
69 log("debug", "Statistics enabled using %s provider, collecting every %d seconds", stats_provider_name, 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
|
70 |
|
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
|
71 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
|
72 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
|
73 |
|
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 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
|
75 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
|
76 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
|
77 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
|
78 |
|
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 if stats.get_stats 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
|
80 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
|
81 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
|
82 -- 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
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 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
|
93 local mark_processing_done = mark_processing_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
|
94 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
|
95 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
|
96 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
|
97 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
|
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 timer.add_task(stats_interval, 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
|
100 prosody.events.add_handler("server-started", function () collect() end, -1); |
|
9804
7929e0fe0577
core.statsmanager: Do a final collection on shutdown
Kim Alvefur <zash@zash.se>
parents:
7664
diff
changeset
|
101 prosody.events.add_handler("server-stopped", function () collect() end, -1); |
|
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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 |
|
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 |
|
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 return { |
|
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 end; |
|
6910
82765a4ec799
statsmanager: Add get() method
Matthew Wild <mwild1@gmail.com>
parents:
6582
diff
changeset
|
116 get = function (name) |
|
82765a4ec799
statsmanager: Add get() method
Matthew Wild <mwild1@gmail.com>
parents:
6582
diff
changeset
|
117 return latest_stats[name], stats_extra[name]; |
|
82765a4ec799
statsmanager: Add get() method
Matthew Wild <mwild1@gmail.com>
parents:
6582
diff
changeset
|
118 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
|
119 }; |
