comparison mod_measure_client_features/mod_measure_client_features.lua @ 6160:3e0bce07f66c

mod_measure_client_features: Switch to the more modern statistics API
author Link Mauve <linkmauve@linkmauve.fr>
date Tue, 04 Feb 2025 23:02:17 +0100
parents 5fdbf416bd40
children
comparison
equal deleted inserted replaced
6159:5aea64434756 6160:3e0bce07f66c
1 module:set_global(); 1 module:set_global();
2 2
3 local measure = require"core.statsmanager".measure; 3 local statsmanager = require "prosody.core.statsmanager";
4
5 local measure_features = module:metric("gauge", "features", "", "Features advertized by clients", {"feature"});
4 6
5 local disco_ns = "http://jabber.org/protocol/disco#info"; 7 local disco_ns = "http://jabber.org/protocol/disco#info";
6
7 local counters = {
8 total = measure("amount", "client_features.total");
9 };
10 8
11 module:hook("stats-update", function () 9 module:hook("stats-update", function ()
12 local total = 0; 10 local total = 0;
13 local buckets = {}; 11 local buckets = {};
14 for _, session in pairs(prosody.full_sessions) do 12 for _, session in pairs(prosody.full_sessions) do
24 end 22 end
25 end 23 end
26 total = total + 1; 24 total = total + 1;
27 end 25 end
28 end 26 end
27 statsmanager.cork();
28 measure_features:clear();
29 for bucket, count in pairs(buckets) do 29 for bucket, count in pairs(buckets) do
30 if counters[bucket] == nil then 30 measure_features:with_labels(bucket):add(count);
31 counters[bucket] = measure("amount", "client_features."..bucket);
32 end
33 counters[bucket](count);
34 end 31 end
35 counters.total(total); 32 measure_features:with_labels("total"):add(total);
33 statsmanager.uncork();
36 end) 34 end)