Mercurial > prosody-modules
comparison mod_measure_client_identities/mod_measure_client_identities.lua @ 3135:e166ccc7a779
mod_measure_client_identities: Collect statistics about client identities.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 22 Jun 2018 01:06:18 +0200 |
parents | |
children | fdbf7c2aed7b |
comparison
equal
deleted
inserted
replaced
3134:99ac6dda9878 | 3135:e166ccc7a779 |
---|---|
1 module:set_global(); | |
2 | |
3 local measure = require"core.statsmanager".measure; | |
4 | |
5 local counters = { | |
6 unknown = measure("amount", "client_identities.unknown"), | |
7 }; | |
8 | |
9 module:hook("stats-update", function () | |
10 local buckets = { | |
11 unknown = 0, | |
12 }; | |
13 for _, session in pairs(prosody.full_sessions) do | |
14 if session.caps_cache ~= nil then | |
15 local node_string = session.caps_cache.attr.node; | |
16 local node = node_string:match("([^#]+)"); | |
17 if buckets[node] == nil then | |
18 buckets[node] = 0; | |
19 end | |
20 buckets[node] = buckets[node] + 1; | |
21 else | |
22 buckets.unknown = buckets.unknown + 1; | |
23 end | |
24 end | |
25 for bucket, count in pairs(buckets) do | |
26 if counters[bucket] == nil then | |
27 counters[bucket] = measure("amount", "client_identities."..bucket); | |
28 end | |
29 counters[bucket](count); | |
30 end | |
31 end) |