Software /
code /
prosody-modules
Annotate
mod_measure_muc/mod_measure_muc.lua @ 4974:807007913f67
mod_log_json: Prefer native Lua table.pack over Prosody util.table one
Prosody is removing support for Lua 5.1, which was the reason for
util.table.pack to exist in the first place, since Lua 5.2+ provides
table.pack. In prosody rev 5eaf77114fdb everything was switched over to
use table.pack, opening the door for removing util.table.pack at some
point. This change here is to prepare for that future eventuality.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 11 Jul 2022 20:08:41 +0200 |
parent | 3969:39931d727c22 |
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) |