Mercurial > prosody-modules
annotate mod_measure_client_identities/mod_measure_client_identities.lua @ 5173:460f78654864
mod_muc_rtbl: also filter messages
This was a bit tricky because we don't want to run the JIDs
through SHA256 on each message. Took a while to come up with this
simple plan of just caching the SHA256 of the JIDs on the
occupants.
This will leave some dirt in the occupants after unloading the
module, but that should be ok; once they cycle the room, the
hashes will be gone.
This is direly needed, otherwise, there is a tight race between
the moderation activities and the actors joining the room.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 21 Feb 2023 21:37:27 +0100 |
parents | fdbf7c2aed7b |
children |
rev | line source |
---|---|
3135
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 module:set_global(); |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 local measure = require"core.statsmanager".measure; |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 local counters = { |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 unknown = measure("amount", "client_identities.unknown"), |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 }; |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 module:hook("stats-update", function () |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 local buckets = { |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 unknown = 0, |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 }; |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 for _, session in pairs(prosody.full_sessions) do |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 if session.caps_cache ~= nil then |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 local node_string = session.caps_cache.attr.node; |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 local node = node_string:match("([^#]+)"); |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 if buckets[node] == nil then |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 buckets[node] = 0; |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 end |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 buckets[node] = buckets[node] + 1; |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 else |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 buckets.unknown = buckets.unknown + 1; |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 end |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 end |
3136
fdbf7c2aed7b
mod_measure_client_identities: Report 0 instead of the previous value when no client with that identity is left.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3135
diff
changeset
|
25 local visited = {}; |
3135
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 for bucket, count in pairs(buckets) do |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 if counters[bucket] == nil then |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 counters[bucket] = measure("amount", "client_identities."..bucket); |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 end |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 counters[bucket](count); |
3136
fdbf7c2aed7b
mod_measure_client_identities: Report 0 instead of the previous value when no client with that identity is left.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3135
diff
changeset
|
31 visited[bucket] = true; |
fdbf7c2aed7b
mod_measure_client_identities: Report 0 instead of the previous value when no client with that identity is left.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3135
diff
changeset
|
32 end |
fdbf7c2aed7b
mod_measure_client_identities: Report 0 instead of the previous value when no client with that identity is left.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3135
diff
changeset
|
33 for bucket, counter in pairs(counters) do |
fdbf7c2aed7b
mod_measure_client_identities: Report 0 instead of the previous value when no client with that identity is left.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3135
diff
changeset
|
34 if not visited[bucket] then |
fdbf7c2aed7b
mod_measure_client_identities: Report 0 instead of the previous value when no client with that identity is left.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3135
diff
changeset
|
35 counter(0); |
fdbf7c2aed7b
mod_measure_client_identities: Report 0 instead of the previous value when no client with that identity is left.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3135
diff
changeset
|
36 end |
3135
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 end |
e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 end) |