25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Add function for getting room diagnostics

This commit is contained in:
Paweł Chmielowski 2022-09-01 13:37:48 +02:00
parent aaf391b284
commit f624b14636

View File

@ -45,7 +45,7 @@
get_room_serverhost/1,
web_page_host/3,
mod_opt_type/1, mod_options/1,
get_commands_spec/0, find_hosts/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.