summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Wallace <mikewallace1979@googlemail.com>2014-08-04 18:56:26 +0100
committerJay Doane <jaydoane@apache.org>2021-04-19 00:34:24 -0700
commitabc9c53a288e6ed2f43dcef813521961e71b0914 (patch)
treee4ccbdc16a50b30c220bca0fd1cb4aa5b946c568
parentdd57fe1bd0eebf1abaf7793532ed26d3c1114243 (diff)
downloadcouchdb-abc9c53a288e6ed2f43dcef813521961e71b0914.tar.gz
Add check for IOQ active requests
This commit adds a function that calculates the total number of requests in the IOQ disk queues by folding through the output of ioq:get_disk_queues/1. A warning message is returned if the total number of requests exceeds a hardcode threshold, otherwise an info message is returned. The printed messages include the raw output of ioq:get_disk_queues/1. BugzID: 32880
-rw-r--r--src/weatherreport/src/weatherreport_check_ioq.erl78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/weatherreport/src/weatherreport_check_ioq.erl b/src/weatherreport/src/weatherreport_check_ioq.erl
new file mode 100644
index 000000000..3055c5e9c
--- /dev/null
+++ b/src/weatherreport/src/weatherreport_check_ioq.erl
@@ -0,0 +1,78 @@
+%% -------------------------------------------------------------------
+%%
+%% weatherreport - automated diagnostic tools for CouchDB
+%%
+%% Copyright (c) 2014 Cloudant
+%%
+%% This file is provided to you under the Apache License,
+%% Version 2.0 (the "License"); you may not use this file
+%% except in compliance with the License. You may obtain
+%% a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+%% -------------------------------------------------------------------
+
+%% @doc Diagnostic that checks the total number of IOQ requests. If
+%% the total exceeds a configured threshold a warning message will be
+%% sent, otherwise only an information message.
+-module(weatherreport_check_ioq).
+-behaviour(weatherreport_check).
+
+-export([description/0,
+ valid/0,
+ check/0,
+ format/1]).
+
+-define(THRESHOLD, 500).
+
+-spec description() -> string().
+description() ->
+ "Check the total number of active IOQ requests".
+
+-spec valid() -> boolean().
+valid() ->
+ weatherreport_node:can_connect().
+
+-spec total_to_level(integer()) -> atom().
+total_to_level(Total) when Total > ?THRESHOLD ->
+ warning;
+total_to_level(_Total) ->
+ info.
+
+-spec sum_channels(list(), list()) -> list().
+sum_channels([], Acc) ->
+ Acc;
+sum_channels([{_Name, Value} | Rest], Acc) ->
+ sum_channels(Rest, Acc + lists:sum(Value)).
+
+-spec sum_queues(list(), list()) -> list().
+sum_queues([], Acc) ->
+ Acc;
+sum_queues([{channels, {Channels}} | Rest], Acc) ->
+ sum_queues(Rest, sum_channels(Channels, Acc));
+sum_queues([{_Name, Value} | Rest], Acc) ->
+ sum_queues(Rest, Acc + Value).
+
+-spec check() -> [{atom(), term()}].
+check() ->
+ case weatherreport_node:local_command(ioq, get_disk_queues, []) of
+ Queues when is_list(Queues) ->
+ Total = sum_queues(Queues, 0),
+ [{total_to_level(Total), {ioq_requests, Total, Queues}}];
+ Error ->
+ [{warning, {ioq_requests_unknown, Error}}]
+ end.
+
+-spec format(term()) -> {io:format(), [term()]}.
+format({ioq_requests_unknown, Error}) ->
+ {"Could not determine total number of IOQ requests: ~w~n", [Error]};
+format({ioq_requests, Total, Queues}) ->
+ {"Total number of active IOQ requests is: ~w ~w", [Total, Queues]}.