view mod_measure_stanza_counts/mod_measure_stanza_counts.lua @ 4203:c4002aae4ad3

mod_s2s_keepalive: Use timestamp as iq @id RFC 6120 implies that the id attribute must be unique within a stream. This should fix problems with remote servers that enforce uniqueness and don't answer duplicated ids. If it doesn't do that, then at least you can get a guesstimate at round-trip time from the difference between the result iq stanza and the timestamp it was logged without having to go look for when it was sent, or needing to keep state.
author Kim Alvefur <zash@zash.se>
date Wed, 14 Oct 2020 18:02:10 +0200
parents 512405077709
children 33b1b6ff23d8
line wrap: on
line source

module:set_global()

local filters = require"util.filters";

local stanza_kinds = { message = true, presence = true, iq = true };

local function rate(measures, dir)
	return function (stanza, session)
		measures[dir]();
		measures[dir .. "_" .. session.type]();
		if stanza.attr and not stanza.attr.xmlns and stanza_kinds[stanza.name] then
			measures[dir .. "_" .. session.type .. "_" .. stanza.name]();
		end
		return stanza;
	end
end

local measures = setmetatable({}, {
	__index = function (t, name)
		local m = module:measure(name, "rate");
		t[name] = m;
		return m;
	end
});

local function measure_stanza_counts(session)
	filters.add_filter(session, "stanzas/in",  rate(measures, "incoming"));
	filters.add_filter(session, "stanzas/out", rate(measures, "outgoing"));
end

filters.add_filter_hook(measure_stanza_counts);