浏览代码

feat: Visitors stats (#13139)

* fix: Fixes mac occupants check logic.

Now works and with missing muc_access_whitelist option.

* feat: Adds visitor stats.

* squash: Drops check for healthcheck room.
factor2
Дамян Минков 2 年前
父节点
当前提交
275e7b00a9
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 32 次插入2 次删除
  1. 30
    0
      resources/prosody-plugins/mod_fmuc.lua
  2. 2
    2
      resources/prosody-plugins/mod_muc_max_occupants.lua

+ 30
- 0
resources/prosody-plugins/mod_fmuc.lua 查看文件

@@ -25,6 +25,11 @@ local main_domain = string.gsub(module.host, muc_domain_prefix..'.', '');
25 25
 
26 26
 local NICK_NS = 'http://jabber.org/protocol/nick';
27 27
 
28
+-- we send stats for the total number of rooms, total number of participants and total number of visitors
29
+local measure_rooms = module:measure("vnode-rooms", "amount");
30
+local measure_participants = module:measure("vnode-participants", "amount");
31
+local measure_visitors = module:measure("vnode-visitors", "amount");
32
+
28 33
 -- This is the domain of the main prosody that is federating with us;
29 34
 local fmuc_main_domain;
30 35
 
@@ -294,3 +299,28 @@ module:hook('muc-private-message', function(event)
294 299
             "Private messaging is disabled on visitor nodes"));
295 300
     return true;
296 301
 end, 10);
302
+
303
+-- we calculate the stats on the configured interval (60 seconds by default)
304
+module:hook_global("stats-update", function ()
305
+    local participants_count, rooms_count, visitors_count = 0, 0, 0;
306
+
307
+    -- iterate over all rooms
308
+    for room in prosody.hosts[module.host].modules.muc.each_room() do
309
+        rooms_count = rooms_count + 1;
310
+        for _, o in room:each_occupant() do
311
+            if jid.host(o.bare_jid) == main_domain then
312
+                visitors_count = visitors_count + 1;
313
+            else
314
+                participants_count = participants_count + 1;
315
+            end
316
+        end
317
+        -- do not count jicofo
318
+        participants_count = participants_count - 1;
319
+    end
320
+
321
+    measure_rooms(rooms_count);
322
+    measure_visitors(visitors_count);
323
+    measure_participants(participants_count);
324
+end);
325
+
326
+

+ 2
- 2
resources/prosody-plugins/mod_muc_max_occupants.lua 查看文件

@@ -30,7 +30,7 @@ local function check_for_max_occupants(event)
30 30
   end
31 31
   -- If we're a whitelisted user joining the room, don't bother checking the max
32 32
   -- occupants.
33
-  if whitelist and whitelist:contains(domain) or whitelist:contains(user..'@'..domain) then
33
+  if whitelist and (whitelist:contains(domain) or whitelist:contains(user..'@'..domain)) then
34 34
     return;
35 35
   end
36 36
 
@@ -53,7 +53,7 @@ local function check_for_max_occupants(event)
53 53
 		-- from the count.
54 54
 		for _, occupant in room:each_occupant() do
55 55
 			user, domain, res = split_jid(occupant.bare_jid);
56
-			if not whitelist:contains(domain) and not whitelist:contains(user..'@'..domain) then
56
+			if not whitelist or (not whitelist:contains(domain) and not whitelist:contains(user..'@'..domain)) then
57 57
 				slots = slots - 1
58 58
 			end
59 59
 		end

正在加载...
取消
保存