comparison mod_measure_client_features/mod_measure_client_features.lua @ 3374:5fdbf416bd40

mod_measure_client_features: Add a module to count the features of each connected client
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 11 Nov 2018 14:44:27 +0100
parents
children
comparison
equal deleted inserted replaced
3373:322e8e7ba7d4 3374:5fdbf416bd40
1 module:set_global();
2
3 local measure = require"core.statsmanager".measure;
4
5 local disco_ns = "http://jabber.org/protocol/disco#info";
6
7 local counters = {
8 total = measure("amount", "client_features.total");
9 };
10
11 module:hook("stats-update", function ()
12 local total = 0;
13 local buckets = {};
14 for _, session in pairs(prosody.full_sessions) do
15 local disco_info = session.caps_cache;
16 if disco_info ~= nil then
17 for feature in disco_info:childtags("feature", disco_ns) do
18 local var = feature.attr.var;
19 if var ~= nil then
20 if buckets[var] == nil then
21 buckets[var] = 0;
22 end
23 buckets[var] = buckets[var] + 1;
24 end
25 end
26 total = total + 1;
27 end
28 end
29 for bucket, count in pairs(buckets) do
30 if counters[bucket] == nil then
31 counters[bucket] = measure("amount", "client_features."..bucket);
32 end
33 counters[bucket](count);
34 end
35 counters.total(total);
36 end)