From f624b146369d473332e023bfca131b689402ca42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= Date: Thu, 1 Sep 2022 13:37:48 +0200 Subject: [PATCH] Add function for getting room diagnostics --- src/mod_muc_admin.erl | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 9651cfe11..f29a5b56f 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -41,11 +41,11 @@ set_room_affiliation/4, get_room_affiliations/2, get_room_affiliation/3, web_menu_main/2, web_page_main/2, web_menu_host/3, subscribe_room/4, subscribe_room_many/3, - unsubscribe_room/2, get_subscribers/2, - get_room_serverhost/1, - web_page_host/3, - mod_opt_type/1, mod_options/1, - get_commands_spec/0, find_hosts/1]). + unsubscribe_room/2, get_subscribers/2, + get_room_serverhost/1, + web_page_host/3, + mod_opt_type/1, mod_options/1, + get_commands_spec/0, find_hosts/1, room_diagnostics/2]). -include("logger.hrl"). -include_lib("xmpp/include/xmpp.hrl"). @@ -1184,6 +1184,28 @@ get_room_pid(Name, Service) -> invalid_service end. +room_diagnostics(Name, Service) -> + try get_room_serverhost(Service) of + ServerHost -> + RMod = gen_mod:ram_db_mod(ServerHost, mod_muc), + case RMod:find_online_room(ServerHost, Name, Service) of + error -> + room_hibernated; + {ok, Pid} -> + case rpc:pinfo(Pid, [current_stacktrace, message_queue_len, messages]) of + [{_, R}, {_, QL}, {_, Q}] -> + #{stacktrace => R, queue_size => QL, queue => lists:sublist(Q, 10)}; + _ -> + unable_to_probe_process + end + end + catch + error:{invalid_domain, _} -> + invalid_service; + error:{unregistered_route, _} -> + invalid_service + end. + %% It is required to put explicitly all the options because %% the record elements are replaced at compile time. %% So, this can't be parametrized.