summaryrefslogtreecommitdiff
path: root/src/ejabberd_system_monitor.erl
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2009-02-13 19:27:56 +0000
committerBadlop <badlop@process-one.net>2009-02-13 19:27:56 +0000
commit3524172856fea6cc5be3e0987f1acb3fd1524d0b (patch)
tree9bc3a9aaf657ac377a9ec108dbe13a2891fd95b3 /src/ejabberd_system_monitor.erl
parentprevent from calling get_vh_registered_users/2 when not available (diff)
* src/ejabberd_system_monitor.erl: Allow parametrizable watchdog
threshold: option watchdog_large_heap or chatting with the watchdog bot (EJAB-545) * src/ejabberd_config.erl: Likewise * doc/guide.tex: Likewise * doc/guide.html: Likewise SVN Revision: 1872
Diffstat (limited to '')
-rw-r--r--src/ejabberd_system_monitor.erl47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/ejabberd_system_monitor.erl b/src/ejabberd_system_monitor.erl
index 5fa2cc4d..505b0994 100644
--- a/src/ejabberd_system_monitor.erl
+++ b/src/ejabberd_system_monitor.erl
@@ -51,7 +51,12 @@
%% Description: Starts the server
%%--------------------------------------------------------------------
start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+ LH = case ejabberd_config:get_local_option(watchdog_large_heap) of
+ I when is_integer(I) -> I;
+ _ -> 1000000
+end,
+ Opts = [{large_heap, LH}],
+ gen_server:start_link({local, ?MODULE}, ?MODULE, Opts, []).
process_command(From, To, Packet) ->
case To of
@@ -90,9 +95,10 @@ process_command(From, To, Packet) ->
%% {stop, Reason}
%% Description: Initiates the server
%%--------------------------------------------------------------------
-init([]) ->
+init(Opts) ->
+ LH = proplists:get_value(large_heap, Opts),
process_flag(priority, high),
- erlang:system_monitor(self(), [{large_heap, 1000000}]),
+ erlang:system_monitor(self(), [{large_heap, LH}]),
lists:foreach(
fun(Host) ->
ejabberd_hooks:add(local_send_to_resource_hook, Host,
@@ -109,10 +115,24 @@ init([]) ->
%% {stop, Reason, State}
%% Description: Handling call messages
%%--------------------------------------------------------------------
+handle_call({get, large_heap}, _From, State) ->
+ {reply, get_large_heap(), State};
+handle_call({set, large_heap, NewValue}, _From, State) ->
+ MonSettings = erlang:system_monitor(self(), [{large_heap, NewValue}]),
+ OldLH = get_large_heap(MonSettings),
+ NewLH = get_large_heap(),
+ {reply, {lh_changed, OldLH, NewLH}, State};
handle_call(_Request, _From, State) ->
Reply = ok,
{reply, Reply, State}.
+get_large_heap() ->
+ MonSettings = erlang:system_monitor(),
+ get_large_heap(MonSettings).
+get_large_heap(MonSettings) ->
+ {_MonitorPid, Options} = MonSettings,
+ proplists:get_value(large_heap, Options).
+
%%--------------------------------------------------------------------
%% Function: handle_cast(Msg, State) -> {noreply, State} |
%% {noreply, State, Timeout} |
@@ -165,7 +185,7 @@ process_large_heap(Pid, Info) ->
JIDs /= [] ->
DetailedInfo = detailed_info(Pid),
Body = io_lib:format(
- "(~w) The process ~w is consuming too much memory: ~w.~n"
+ "(~w) The process ~w is consuming too much memory:~n~p~n"
"~s",
[node(), Pid, Info, DetailedInfo]),
From = jlib:make_jid("", Host, "watchdog"),
@@ -303,14 +323,25 @@ process_command1(From, To, Body) ->
process_command2(["kill", SNode, SPid], From, To) ->
Node = list_to_atom(SNode),
remote_command(Node, [kill, SPid], From, To);
+process_command2(["showlh", SNode], From, To) ->
+ Node = list_to_atom(SNode),
+ remote_command(Node, [showlh], From, To);
+process_command2(["setlh", SNode, NewValueString], From, To) ->
+ Node = list_to_atom(SNode),
+ NewValue = list_to_integer(NewValueString),
+ remote_command(Node, [setlh, NewValue], From, To);
process_command2(["help"], From, To) ->
send_message(To, From, help());
process_command2(_, From, To) ->
send_message(To, From, help()).
+
help() ->
"Commands:\n"
- " kill <node> <pid>".
+ " kill <node> <pid>\n"
+ " showlh <node>\n"
+ " setlh <node> <integer>".
+
remote_command(Node, Args, From, To) ->
Message =
@@ -325,6 +356,12 @@ remote_command(Node, Args, From, To) ->
process_remote_command([kill, SPid]) ->
exit(list_to_pid(SPid), kill),
"ok";
+process_remote_command([showlh]) ->
+ Res = gen_server:call(ejabberd_system_monitor, {get, large_heap}),
+ io_lib:format("Current large heap: ~p", [Res]);
+process_remote_command([setlh, NewValue]) ->
+ {lh_changed, OldLH, NewLH} = gen_server:call(ejabberd_system_monitor, {set, large_heap, NewValue}),
+ io_lib:format("Result of set large heap: ~p --> ~p", [OldLH, NewLH]);
process_remote_command(_) ->
throw(unknown_command).