diff options
author | Mike Wallace <mikewallace1979@googlemail.com> | 2014-08-21 13:08:30 +0100 |
---|---|---|
committer | Jay Doane <jaydoane@apache.org> | 2021-04-19 00:35:19 -0700 |
commit | 9fb7d72eee1b524d25c83d6429d43b47fb21df4b (patch) | |
tree | d6a7c8055cf5d5b13942d778a708ef5708660fa4 | |
parent | 49d1fdeb1b210b9763d82aa0493d383535ec73dd (diff) | |
download | couchdb-9fb7d72eee1b524d25c83d6429d43b47fb21df4b.tar.gz |
Generalise threshold checks on process attributes
This commit generalises the logic that checks for process
attributes and moves it to weatherreport_utils. This is
groundwork for the following commit which will add a check
for processes by memory usage by re-using the generalised code.
We also take the opportunity to rename fold_processes to
something that is more descriptive and also correct.
BugzID: 32875
-rw-r--r-- | src/weatherreport/src/weatherreport_check_message_queues.erl | 32 | ||||
-rw-r--r-- | src/weatherreport/src/weatherreport_util.erl | 31 |
2 files changed, 37 insertions, 26 deletions
diff --git a/src/weatherreport/src/weatherreport_check_message_queues.erl b/src/weatherreport/src/weatherreport_check_message_queues.erl index 3633ae3f1..ae99ff4dc 100644 --- a/src/weatherreport/src/weatherreport_check_message_queues.erl +++ b/src/weatherreport/src/weatherreport_check_message_queues.erl @@ -41,35 +41,17 @@ description() -> valid() -> weatherreport_node:can_connect(). -fold_processes([], Acc, _Opts) -> - Acc; -fold_processes([{Pid, MBoxSize, Info} | T], Acc, Opts) when MBoxSize < ?THRESHOLD -> - Message = {info, {mbox_ok, {Pid, MBoxSize, Info}}}, - fold_processes(T, [Message | Acc], Opts); -fold_processes([{Pid, MBoxSize, Info} | T], Acc, Opts) -> - Message = case proplists:get_value(expert, Opts) of - true -> - Pinfo = weatherreport_node:local_command(recon, info, [Pid]), - {warning, {mbox_large, {Pid, MBoxSize, Info, Pinfo}}}; - _ -> - {warning, {mbox_large, {Pid, MBoxSize, Info}}} - end, - fold_processes(T, [Message | Acc], Opts). - -spec check(list()) -> [{atom(), term()}]. check(Opts) -> - Processes = weatherreport_node:local_command( - recon, - proc_count, - [message_queue_len, 10] - ), - fold_processes(Processes, [], Opts). + weatherreport_util:check_proc_count( + message_queue_len, + ?THRESHOLD, + Opts). -spec format(term()) -> {io:format(), [term()]}. -format({mbox_large, {Pid, MBoxSize, Info, Pinfo}}) -> +format({high, {Pid, MBoxSize, Info, Pinfo}}) -> {"Process ~w has excessive mailbox size of ~w: ~w ~w", [Pid, MBoxSize, Info, Pinfo]}; -format({mbox_large, {Pid, MBoxSize, Info}}) -> +format({high, {Pid, MBoxSize, Info}}) -> {"Process ~w has excessive mailbox size of ~w: ~w", [Pid, MBoxSize, Info]}; -format({mbox_ok, {Pid, MBoxSize, Info}}) -> +format({ok, {Pid, MBoxSize, Info}}) -> {"Process ~w has mailbox size of ~w: ~w", [Pid, MBoxSize, Info]}. - diff --git a/src/weatherreport/src/weatherreport_util.erl b/src/weatherreport/src/weatherreport_util.erl index a7957922f..ab5370812 100644 --- a/src/weatherreport/src/weatherreport_util.erl +++ b/src/weatherreport/src/weatherreport_util.erl @@ -33,7 +33,8 @@ log/3,log/4, binary_to_float/1, should_log/1, - flush_stdout/0]). + flush_stdout/0, + check_proc_count/3]). %% @doc Converts a check module name into a short name that can be %% used to refer to a check on the command line. For example, @@ -113,3 +114,31 @@ should_log(Level) -> flush_stdout() -> timer:sleep(1000). + +%% @doc Utility function to check processes based on an attribute returned +%% by recon:proc_count/2. +-spec check_proc_count(atom(), integer(), list()) -> [{atom(), term()}]. +check_proc_count(Key, Threshold, Opts) -> + Processes = weatherreport_node:local_command(recon, proc_count, [Key, 10]), + procs_to_messages(Processes, Threshold, [], Opts). + +%% @doc Utility function to convert the list of process info returned by +%% recon:proc_count/2 into a list of diagnostic messages. +-spec procs_to_messages(list(), integer(), list(), list()) -> [{atom(), term()}]. +procs_to_messages([], _Threshold, Acc, _Opts) -> + Acc; +procs_to_messages([{Pid, Value, Info} | T], Threshold, Acc, Opts) -> + Level = case Value > Threshold of + true -> warning; + _ -> info + end, + Message = case {Level, proplists:get_value(expert, Opts)} of + {warning, true} -> + Pinfo = weatherreport_node:local_command(recon, info, [Pid]), + {warning, {high, {Pid, Value, Info, Pinfo}}}; + {warning, _} -> + {warning, {high, {Pid, Value, Info}}}; + {info, _} -> + {info, {ok, {Pid, Value, Info}}} + end, + procs_to_messages(T, Threshold, [Message | Acc], Opts). |