Mercurial > prosody-modules
annotate mod_measure_muc/mod_measure_muc.lua @ 5298:12f7d8b901e0
mod_audit: Support for adding location (GeoIP) to audit events
This can be more privacy-friendly than logging full IP addresses, and also
more informative to a user - IP addresses don't mean much to the average
person, however if they see activity from outside their expected country, they
can immediately identify suspicious activity.
As with IPs, this field is configurable for deployments that would like to
disable it. Location is also not logged when the geoip library is not
available.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 01 Apr 2023 13:11:53 +0100 |
parents | 39931d727c22 |
children |
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) |