changeset 3969:39931d727c22

mod_measure_muc: Collect statistics on Grout Chat
author kaliko <kaliko@azylum.org>
date Tue, 07 Apr 2020 18:48:04 +0200 (2020-04-07)
parents bf5d91769f99
children e0f3e29ab18a
files mod_measure_muc/README.markdown mod_measure_muc/mod_measure_muc.lua
diffstat 2 files changed, 94 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_measure_muc/README.markdown	Tue Apr 07 18:48:04 2020 +0200
@@ -0,0 +1,38 @@
+---
+labels:
+- Statistics
+summary: Collect statistics on Grout Chat
+...
+
+Description
+===========
+
+This module collects statistics from group chat component.
+
+It collects current count of hidden, persistent, archive-enabled, password
+protected rooms. The current count of room is also exposed (hidden+public).
+
+
+Configuration
+=============
+
+mod\_measure\_muc must be load on MUC components (not globally):
+
+```lua
+Component "conference.example.com" "muc"
+		modules_enabled = {
+			"measure_muc";
+		}
+```
+
+See also the documentation of Prosody’s [MUC module](https://prosody.im/doc/modules/mod_muc).
+
+Compatibility
+=============
+
+  ------- -------------
+  trunk   Works
+  0.11    Works
+  0.10    Unknown
+  0.9     Does not work
+  ------- -------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_measure_muc/mod_measure_muc.lua	Tue Apr 07 18:48:04 2020 +0200
@@ -0,0 +1,56 @@
+-- Group Chat statistics
+--
+-- Copyright (C) 2020 kaliko <kaliko@azylum.org>
+--
+-- This module is MIT/X11 licensed.
+
+-- https://prosody.im/doc/developers/modules
+-- https://prosody.im/doc/developers/moduleapi
+-- https://prosody.im/doc/statistics
+
+module:log("info", "loading mod_%s", module.name);
+if module:get_host_type() ~= "component" then
+	module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name);
+	return;
+end
+
+local mod_muc = module:depends"muc";
+local all_rooms = rawget(mod_muc, "all_rooms")
+
+-- Add relevant boolean MUC metrics here
+local counters = {
+	hidden = module:measure("hidden", "amount", 0),
+	persistent = module:measure("persistent", "amount", 0),
+	password = module:measure('passwd', "amount", 0),
+	archiving = module:measure('archiving', 'amount', 0),
+};
+local total_counter = module:measure("total", "amount", 0);
+
+module:hook_global("stats-update", function ()
+	local total = 0;
+	local buckets = {};
+	-- Init buckets
+	for bucket, _ in pairs(counters) do
+		buckets[bucket] = 0;
+	end
+	for room in all_rooms() do
+		--[[
+		module:log('debug', 'room data for : "'..room.jid..'"');
+		for conf, val in pairs(room._data) do
+			module:log('debug', conf..": "..tostring(val));
+		end
+		]]--
+		total = total + 1;
+		--module:log('debug','buckets room data :');
+		for bucket, _ in pairs(buckets) do
+			--module:log('debug', bucket..": "..tostring(room._data[bucket]));
+			if room._data[bucket] then
+				buckets[bucket] = buckets[bucket] + 1;
+			end
+		end
+	end
+	for bucket, count in pairs(buckets) do
+		counters[bucket](count)
+	end
+	total_counter(total);
+end)