# HG changeset patch # User Matthew Wild # Date 1760380970 -3600 # Node ID 4c98f4340bf1161cc3c843fae68eb01ac0af9dcf # Parent fa976338928c0ce6aa1626258859ea525cdd16ed mod_measure_pending_s2s: New module to measure pending s2s/stanzas diff -r fa976338928c -r 4c98f4340bf1 mod_measure_pending_s2s/README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_measure_pending_s2s/README.md Mon Oct 13 19:42:50 2025 +0100 @@ -0,0 +1,13 @@ +--- +labels: +- Statistics +- Stage-Alpha +summary: Measure pending s2s connections and stanzas +... + +Description +=========== + +This module measures the number of outgoing s2s connections which are not +fully established yet, and the number of stanzas queued for delivery until +they are established. diff -r fa976338928c -r 4c98f4340bf1 mod_measure_pending_s2s/mod_measure_pending_s2s.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_measure_pending_s2s/mod_measure_pending_s2s.lua Mon Oct 13 19:42:50 2025 +0100 @@ -0,0 +1,40 @@ +module:set_global(); + +local measure_pending_connections = module:metric( + "gauge", "connections_pending_outbound", "", + "In-progress outbound s2s connections", + {"host"} +); + +local measure_pending_stanzas = module:metric( + "gauge", "stanzas_pending_outbound", "", + "Outbound s2s stanzas queued for delivery", + {"host"} +); + +local hosts = {}; + +function module.add_host(host_module) + hosts[host_module.host] = true; + function host_module.unload() + hosts[host_module.host] = nil; + end +end + +module:hook("stats-update", function () + + for host in pairs(hosts) do + local n_pending_sessions = 0; + local n_pending_stanzas = 0; + + for _, session in pairs(prosody.hosts[host].s2sout) do + if session.sendq then + n_pending_sessions = n_pending_sessions + 1; + n_pending_stanzas = n_pending_stanzas + session.sendq:count(); + end + end + + measure_pending_connections:with_labels(host):set(n_pending_sessions); + measure_pending_stanzas:with_labels(host):set(n_pending_stanzas); + end +end);