mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API

Mon, 09 Oct 2017 20:15:33 +0200

author
Kim Alvefur <zash@zash.se>
date
Mon, 09 Oct 2017 20:15:33 +0200
changeset 2787
750572f6f59d
parent 2786
127d5452e4bb
child 2788
512405077709

mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API

mod_measure_stanza_counts/README.markdown file | annotate | diff | comparison | revisions
mod_measure_stanza_counts/mod_measure_stanza_counts.lua file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_measure_stanza_counts/README.markdown	Mon Oct 09 20:15:33 2017 +0200
@@ -0,0 +1,9 @@
+---
+summary: Collect statistics on number of stanzas processed
+---
+
+Description
+===========
+
+This module measures the number of stanzas handled and reports using
+Prosody 0.10 APIs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_measure_stanza_counts/mod_measure_stanza_counts.lua	Mon Oct 09 20:15:33 2017 +0200
@@ -0,0 +1,31 @@
+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 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);

mercurial