Software / code / prosody-modules
Annotate
mod_measure_client_features/mod_measure_client_features.lua @ 6319:63ef69b2f046
mod_http_oauth2: Assume Prosody 13.0+ roles are available
Per the README, 0.12 is not supported, so we should not need to worry
about this. Plus it is assumed to be present elsewhere and that would
throw errors.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 02 Jul 2025 16:15:32 +0200 |
| parent | 6188:3e0bce07f66c |
| rev | line source |
|---|---|
|
3374
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 module:set_global(); |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
|
6188
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
3 local statsmanager = require "prosody.core.statsmanager"; |
|
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
4 |
|
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
5 local measure_features = module:metric("gauge", "features", "", "Features advertized by clients", {"feature"}); |
|
3374
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 local disco_ns = "http://jabber.org/protocol/disco#info"; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 module:hook("stats-update", function () |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 local total = 0; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 local buckets = {}; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 for _, session in pairs(prosody.full_sessions) do |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 local disco_info = session.caps_cache; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 if disco_info ~= nil then |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 for feature in disco_info:childtags("feature", disco_ns) do |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 local var = feature.attr.var; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 if var ~= nil then |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 if buckets[var] == nil then |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 buckets[var] = 0; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 end |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 buckets[var] = buckets[var] + 1; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 end |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 end |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 total = total + 1; |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 end |
|
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 end |
|
6188
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
27 statsmanager.cork(); |
|
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
28 measure_features:clear(); |
|
3374
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 for bucket, count in pairs(buckets) do |
|
6188
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
30 measure_features:with_labels(bucket):add(count); |
|
3374
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 end |
|
6188
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
32 measure_features:with_labels("total"):add(total); |
|
3e0bce07f66c
mod_measure_client_features: Switch to the more modern statistics API
Link Mauve <linkmauve@linkmauve.fr>
parents:
3374
diff
changeset
|
33 statsmanager.uncork(); |
|
3374
5fdbf416bd40
mod_measure_client_features: Add a module to count the features of each connected client
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 end) |