changeset 6342:4c98f4340bf1

mod_measure_pending_s2s: New module to measure pending s2s/stanzas
author Matthew Wild <mwild1@gmail.com>
date Mon, 13 Oct 2025 19:42:50 +0100
parents fa976338928c
children ee2ebdec1fae
files mod_measure_pending_s2s/README.md mod_measure_pending_s2s/mod_measure_pending_s2s.lua
diffstat 2 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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.
--- /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);