Software /
code /
prosody-modules
Comparison
mod_measure_muc/mod_measure_muc.lua @ 3969:39931d727c22
mod_measure_muc: Collect statistics on Grout Chat
author | kaliko <kaliko@azylum.org> |
---|---|
date | Tue, 07 Apr 2020 18:48:04 +0200 |
comparison
equal
deleted
inserted
replaced
3968:bf5d91769f99 | 3969:39931d727c22 |
---|---|
1 -- Group Chat statistics | |
2 -- | |
3 -- Copyright (C) 2020 kaliko <kaliko@azylum.org> | |
4 -- | |
5 -- This module is MIT/X11 licensed. | |
6 | |
7 -- https://prosody.im/doc/developers/modules | |
8 -- https://prosody.im/doc/developers/moduleapi | |
9 -- https://prosody.im/doc/statistics | |
10 | |
11 module:log("info", "loading mod_%s", module.name); | |
12 if module:get_host_type() ~= "component" then | |
13 module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name); | |
14 return; | |
15 end | |
16 | |
17 local mod_muc = module:depends"muc"; | |
18 local all_rooms = rawget(mod_muc, "all_rooms") | |
19 | |
20 -- Add relevant boolean MUC metrics here | |
21 local counters = { | |
22 hidden = module:measure("hidden", "amount", 0), | |
23 persistent = module:measure("persistent", "amount", 0), | |
24 password = module:measure('passwd', "amount", 0), | |
25 archiving = module:measure('archiving', 'amount', 0), | |
26 }; | |
27 local total_counter = module:measure("total", "amount", 0); | |
28 | |
29 module:hook_global("stats-update", function () | |
30 local total = 0; | |
31 local buckets = {}; | |
32 -- Init buckets | |
33 for bucket, _ in pairs(counters) do | |
34 buckets[bucket] = 0; | |
35 end | |
36 for room in all_rooms() do | |
37 --[[ | |
38 module:log('debug', 'room data for : "'..room.jid..'"'); | |
39 for conf, val in pairs(room._data) do | |
40 module:log('debug', conf..": "..tostring(val)); | |
41 end | |
42 ]]-- | |
43 total = total + 1; | |
44 --module:log('debug','buckets room data :'); | |
45 for bucket, _ in pairs(buckets) do | |
46 --module:log('debug', bucket..": "..tostring(room._data[bucket])); | |
47 if room._data[bucket] then | |
48 buckets[bucket] = buckets[bucket] + 1; | |
49 end | |
50 end | |
51 end | |
52 for bucket, count in pairs(buckets) do | |
53 counters[bucket](count) | |
54 end | |
55 total_counter(total); | |
56 end) |