annotate mod_measure_muc/mod_measure_muc.lua @ 4365:f975a4d31f35

mod_http_admin_api: make the api a bit less untested (read: fix bugs)
author Jonas Schäfer <jonas@wielicki.name>
date Thu, 21 Jan 2021 16:13:29 +0100
parents 39931d727c22
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3969
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
1 -- Group Chat statistics
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
2 --
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
3 -- Copyright (C) 2020 kaliko <kaliko@azylum.org>
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
4 --
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
5 -- This module is MIT/X11 licensed.
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
6
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
7 -- https://prosody.im/doc/developers/modules
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
8 -- https://prosody.im/doc/developers/moduleapi
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
9 -- https://prosody.im/doc/statistics
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
10
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
11 module:log("info", "loading mod_%s", module.name);
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
12 if module:get_host_type() ~= "component" then
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
13 module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name);
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
14 return;
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
15 end
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
16
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
17 local mod_muc = module:depends"muc";
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
18 local all_rooms = rawget(mod_muc, "all_rooms")
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
19
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
20 -- Add relevant boolean MUC metrics here
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
21 local counters = {
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
22 hidden = module:measure("hidden", "amount", 0),
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
23 persistent = module:measure("persistent", "amount", 0),
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
24 password = module:measure('passwd', "amount", 0),
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
25 archiving = module:measure('archiving', 'amount', 0),
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
26 };
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
27 local total_counter = module:measure("total", "amount", 0);
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
28
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
29 module:hook_global("stats-update", function ()
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
30 local total = 0;
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
31 local buckets = {};
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
32 -- Init buckets
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
33 for bucket, _ in pairs(counters) do
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
34 buckets[bucket] = 0;
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
35 end
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
36 for room in all_rooms() do
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
37 --[[
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
38 module:log('debug', 'room data for : "'..room.jid..'"');
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
39 for conf, val in pairs(room._data) do
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
40 module:log('debug', conf..": "..tostring(val));
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
41 end
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
42 ]]--
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
43 total = total + 1;
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
44 --module:log('debug','buckets room data :');
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
45 for bucket, _ in pairs(buckets) do
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
46 --module:log('debug', bucket..": "..tostring(room._data[bucket]));
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
47 if room._data[bucket] then
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
48 buckets[bucket] = buckets[bucket] + 1;
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
49 end
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
50 end
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
51 end
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
52 for bucket, count in pairs(buckets) do
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
53 counters[bucket](count)
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
54 end
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
55 total_counter(total);
39931d727c22 mod_measure_muc: Collect statistics on Grout Chat
kaliko <kaliko@azylum.org>
parents:
diff changeset
56 end)