Software /
code /
prosody
Annotate
core/statsmanager.lua @ 12504:c589874fe348
mod_smacks: Initialize queue before sending <enable>
Setting the .smacks field enables code paths that expects the queue to
be present. The queue is initialized in wrap_session_out(). With
opportunistic writes enabled this happens immediately on .sends2s(), so
the sending <enable> must happen before OR after these two lines, not in
the middle.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 15 May 2022 16:12:34 +0200 |
parent | 11575:76d32b2ca5eb |
child | 12972:ead41e25ebc0 |
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; |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
6 local array = require "util.array"; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
7 local timed = require "util.openmetrics".timed; |
6554
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
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
|
9 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
|
10 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
|
11 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
|
12 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
|
13 end |
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
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
|
15 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
|
16 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
|
17 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
|
18 |
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 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
|
20 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
|
21 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
|
22 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
|
23 end |
11515
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
24 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
|
25 stats_interval = nil; |
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
26 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
|
27 |
1c8b63fe6472
statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents:
6910
diff
changeset
|
28 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
|
29 internal = "util.statistics"; |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
7521
diff
changeset
|
30 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
|
31 }; |
1c8b63fe6472
statsmanager: Add 'stats_provider' option, to allow selecting alternative API providers to util.statistics
Matthew Wild <mwild1@gmail.com>
parents:
6910
diff
changeset
|
32 |
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
|
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 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
|
35 |
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 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 |
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 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
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 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
|
57 |
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
|
58 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
|
59 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
|
60 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
|
61 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
62 local measure, collect, metric, cork, uncork; |
6554
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 |
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
|
64 if stats then |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
65 function metric(type_, name, unit, description, labels, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
66 local registry = stats.metric_registry |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
67 local f = assert(registry[type_], "unknown metric family type: "..type_); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
68 return f(registry, name, unit or "", description or "", labels, extra); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
69 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
70 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
71 local function new_legacy_metric(stat_type, name, unit, description, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
72 local label_keys = array() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
73 local conf = extra or {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
74 if fixed_label_key then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
75 label_keys:push(fixed_label_key) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
76 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
77 unit = unit or "" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
78 local mf = metric(stat_type, "prosody_" .. name, unit, description, label_keys, conf); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
79 if fixed_label_key then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
80 mf = mf:with_partial_label(fixed_label_value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
81 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
82 return mf:with_labels() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
83 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
84 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
85 local function unwrap_legacy_extra(extra, type_, name, unit) |
11575
76d32b2ca5eb
statsmanager: remove "legacy" wording
Jonas Schäfer <jonas@wielicki.name>
parents:
11523
diff
changeset
|
86 local description = extra and extra.description or name.." "..type_ |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
87 unit = extra and extra.unit or unit |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
88 return description, unit |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
89 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
90 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
91 -- These wrappers provide the pre-OpenMetrics interface of statsmanager |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
92 -- and moduleapi (module:measure). |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
93 local legacy_metric_wrappers = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
94 amount = function(name, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
95 local initial = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
96 if type(extra) == "number" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
97 initial = extra |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
98 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
99 initial = extra and extra.initial or initial |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
100 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
101 local description, unit = unwrap_legacy_extra(extra, "amount", name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
102 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
103 local m = new_legacy_metric("gauge", name, unit, description, fixed_label_key, fixed_label_value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
104 m:set(initial or 0) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
105 return function(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
106 m:set(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
107 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
108 end; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
109 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
110 counter = function(name, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
111 if type(extra) == "number" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
112 -- previous versions of the API allowed passing an initial |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
113 -- value here; we do not allow that anymore, it is not a thing |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
114 -- which makes sense with counters |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
115 extra = nil |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
116 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
117 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
118 local description, unit = unwrap_legacy_extra(extra, "counter", name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
119 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
120 local m = new_legacy_metric("counter", name, unit, description, fixed_label_key, fixed_label_value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
121 m:set(0) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
122 return function(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
123 m:add(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
124 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
125 end; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
126 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
127 rate = function(name, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
128 if type(extra) == "number" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
129 -- previous versions of the API allowed passing an initial |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
130 -- value here; we do not allow that anymore, it is not a thing |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
131 -- which makes sense with counters |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
132 extra = nil |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
133 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
134 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
135 local description, unit = unwrap_legacy_extra(extra, "counter", name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
136 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
137 local m = new_legacy_metric("counter", name, unit, description, fixed_label_key, fixed_label_value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
138 m:set(0) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
139 return function() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
140 m:add(1) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
141 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
142 end; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
143 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
144 times = function(name, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
145 local conf = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
146 if extra and extra.buckets then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
147 conf.buckets = extra.buckets |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
148 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
149 conf.buckets = { 0.001, 0.01, 0.1, 1.0, 10.0, 100.0 } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
150 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
151 local description, _ = unwrap_legacy_extra(extra, "times", name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
152 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
153 local m = new_legacy_metric("histogram", name, "seconds", description, fixed_label_key, fixed_label_value, conf) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
154 return function() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
155 return timed(m) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
156 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
157 end; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
158 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
159 sizes = function(name, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
160 local conf = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
161 if extra and extra.buckets then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
162 conf.buckets = extra.buckets |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
163 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
164 conf.buckets = { 1024, 4096, 32768, 131072, 1048576, 4194304, 33554432, 134217728, 1073741824 } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
165 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
166 local description, _ = unwrap_legacy_extra(extra, "sizes", name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
167 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
168 local m = new_legacy_metric("histogram", name, "bytes", description, fixed_label_key, fixed_label_value, conf) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
169 return function(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
170 m:sample(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
171 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
172 end; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
173 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
174 distribution = function(name, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
175 if type(extra) == "string" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
176 -- compat with previous API |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
177 extra = { unit = extra } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
178 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
179 local description, unit = unwrap_legacy_extra(extra, "distribution", name, "") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
180 local m = new_legacy_metric("summary", name, unit, description, fixed_label_key, fixed_label_value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
181 return function(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
182 m:sample(v) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
183 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
184 end; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
185 }; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
186 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
187 -- Argument order switched here to support the legacy statsmanager.measure |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
188 -- interface. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
189 function measure(stat_type, name, extra, fixed_label_key, fixed_label_value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
190 local wrapper = assert(legacy_metric_wrappers[stat_type], "unknown legacy metric type "..stat_type) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
191 return wrapper(name, fixed_label_key, fixed_label_value, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
192 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
193 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
194 if stats.cork then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
195 function cork() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
196 return stats:cork() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
197 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
198 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
199 function uncork() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
200 return stats:uncork() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
201 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
202 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
203 function cork() end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
204 function uncork() 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
|
205 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
|
206 |
11515
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
207 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
|
208 |
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
|
209 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
|
210 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
|
211 |
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
|
212 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
|
213 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
|
214 fire_event("stats-update"); |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
215 -- ensure that the backend is uncorked, in case it got stuck at |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
216 -- some point, to avoid infinite resource use |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
217 uncork() |
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
|
218 mark_collection_done(); |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
219 local manual_result = nil |
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
|
220 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
221 if stats.metric_registry then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
222 -- only if supported by the backend, we fire the event which |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
223 -- provides the current metric values |
11506
9a3ebdd65f9c
core.statsmanager: Cover util.statistics work in processing measurement
Kim Alvefur <zash@zash.se>
parents:
10884
diff
changeset
|
224 local mark_processing_done = mark_processing_start(); |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
225 local metric_registry = stats.metric_registry; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
226 fire_event("openmetrics-updated", { metric_registry = metric_registry }) |
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
|
227 mark_processing_done(); |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
228 manual_result = metric_registry; |
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
|
229 end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
230 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
231 return stats_interval, manual_result; |
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
|
232 end |
11515
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
233 if stats_interval then |
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
234 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
|
235 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
|
236 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
|
237 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
|
238 else |
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 function measure() return measure; end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
247 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
248 local dummy_mt = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
249 function dummy_mt.__newindex() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
250 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
251 function dummy_mt:__index() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
252 return self |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
253 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
254 function dummy_mt:__call() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
255 return self |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
256 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
257 local dummy = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
258 setmetatable(dummy, dummy_mt) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
259 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
260 function metric() return dummy; end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
261 function cork() end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
262 function uncork() 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
|
263 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
|
264 |
11515
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
265 local exported_collect = nil; |
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
266 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
|
267 exported_collect = collect; |
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
268 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
|
269 |
6c22bec3e8d0
statsmanager, prosody: New core module and API for gathering statistics about the running server
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
270 return { |
11515
10d13e0554f9
core.statsmanager: Allow special "manual" value for statistics_interval
Kim Alvefur <zash@zash.se>
parents:
11506
diff
changeset
|
271 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
|
272 measure = measure; |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
273 cork = cork; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
274 uncork = uncork; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
275 metric = metric; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
276 get_metric_registry = function () |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11515
diff
changeset
|
277 return stats and stats.metric_registry or nil |
6910
82765a4ec799
statsmanager: Add get() method
Matthew Wild <mwild1@gmail.com>
parents:
6582
diff
changeset
|
278 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
|
279 }; |