Software /
code /
prosody
Comparison
plugins/mod_csi.lua @ 13026:a97f4b277221
mod_csi: Drop summary stats, doesn't work in normal module
This method ends up going up for each collection and the :clear() method
is only available to global modules (see e.g. mod_c2s), while regular
per-host modules get scoped stats
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 06 Apr 2023 08:36:39 +0200 |
parent | 13025:b7d0c1d75a37 |
child | 13070:be9ac41f1619 |
comparison
equal
deleted
inserted
replaced
13025:b7d0c1d75a37 | 13026:a97f4b277221 |
---|---|
1 local st = require "prosody.util.stanza"; | 1 local st = require "prosody.util.stanza"; |
2 local xmlns_csi = "urn:xmpp:csi:0"; | 2 local xmlns_csi = "urn:xmpp:csi:0"; |
3 local csi_feature = st.stanza("csi", { xmlns = xmlns_csi }); | 3 local csi_feature = st.stanza("csi", { xmlns = xmlns_csi }); |
4 | 4 |
5 local sum = module:metric("gauge", "sessions_per_state", "sessions", "CSI state per session", { "csi_state" }) | |
6 local change = module:metric("counter", "changes", "events", "CSI state changes", {"csi_state"}); | 5 local change = module:metric("counter", "changes", "events", "CSI state changes", {"csi_state"}); |
7 | |
8 module:hook_global("stats-update", function () | |
9 for _, session in pairs(prosody.full_sessions) do | |
10 if session.host == module.host then | |
11 sum:with_labels(session.state or "none"):add(1); | |
12 end | |
13 end | |
14 end); | |
15 | 6 |
16 local csi_handler_available = nil; | 7 local csi_handler_available = nil; |
17 module:hook("stream-features", function (event) | 8 module:hook("stream-features", function (event) |
18 if event.origin.username and csi_handler_available then | 9 if event.origin.username and csi_handler_available then |
19 event.features:add_child(csi_feature); | 10 event.features:add_child(csi_feature); |