Comparison

plugins/mod_csi.lua @ 13025:b7d0c1d75a37

mod_csi: Add metrics, covering changes and totals Motivation: Investigating clients that seem to forget to set CSI. Also, of course, MORE GRAPHS!
author Kim Alvefur <zash@zash.se>
date Thu, 06 Apr 2023 08:01:55 +0200
parent 12977:74b9e05af71e
child 13026:a97f4b277221
comparison
equal deleted inserted replaced
13024:7558fd152459 13025:b7d0c1d75a37
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
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"});
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);
4 15
5 local csi_handler_available = nil; 16 local csi_handler_available = nil;
6 module:hook("stream-features", function (event) 17 module:hook("stream-features", function (event)
7 if event.origin.username and csi_handler_available then 18 if event.origin.username and csi_handler_available then
8 event.features:add_child(csi_feature); 19 event.features:add_child(csi_feature);
11 22
12 function refire_event(name) 23 function refire_event(name)
13 return function (event) 24 return function (event)
14 if event.origin.username then 25 if event.origin.username then
15 event.origin.state = event.stanza.name; 26 event.origin.state = event.stanza.name;
27 change:with_labels(event.stanza.name):add(1);
16 module:fire_event(name, event); 28 module:fire_event(name, event);
17 return true; 29 return true;
18 end 30 end
19 end; 31 end;
20 end 32 end