Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Full refactoring of plugin #3

Merged
merged 6 commits into from

2 participants

@adw0rd

Hello!

We rewrote "nagios_erlang.erl" in order to be able to send multiple applications with commas. Since one has to edit too much.

We also added a flag - host, which replaces the hostname of the node from which the works Nagios (TMP_NODE). And added to the node name is a $ RANDOM, to erl does not conflict with a simultaneous check Nagios.

@lethain
Owner

Fantastic. Would you have any interest in being added as a collaborator on this repo, or me pointing to your fork as the canonical going forward as I've cleanly been a poor maintainer?

@lethain lethain merged commit 9b40fb0 into lethain:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 22, 2013
  1. @adw0rd
  2. @adw0rd
Commits on Feb 24, 2013
  1. @adw0rd

    Refactoring of check_erlang_application.sh, check_erlang_node.sh. Add…

    adw0rd authored
    …ed --host|-H flag to transfer desired hostname.
  2. @adw0rd

    Refactoring of nagios_erlang.erl and changed README. Now the applicat…

    adw0rd authored
    …ion will check all at once rather than one by one; Transfer them to a comma.
Commits on May 6, 2013
  1. memory; processes; ports stat parameters and aliases

    Boris Timokhin authored
  2. @adw0rd

    Merge pull request #1 from ussi/master

    adw0rd authored
    Added check_erlang_statistics.sh
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -0,0 +1 @@
+erl_crash.dump
View
13 README.markdown
@@ -29,13 +29,13 @@ to point to the directory where ``nagios_erlang.beam`` can be found.
### Checking Nodes
- bash-3.2$ ./check_erlang_node.sh -e /usr/bin/erl -n my_node
+ bash-3.2$ ./check_erlang_node.sh -e `which erl` -n my_node -c `cat /path/to/.erlang.cookie`
OK - Node my_node running.
### Checking Applications
- bash-3.2$ ./check_erlang_application.sh -e /usr/bin/erl -n my_node -a application
- OK - Application application running at my_node.
+ bash-3.2$ ./check_erlang_application.sh -e `which erl` -n my_node -c `cat /path/to/.erlang.cookie` -a application1,application2
+ OK - Applications ["application1","application2"] running on Node my_node.
### Checking Process Groups
@@ -67,11 +67,8 @@ application which doesn't exist, while kernel is a real application which
is indeed running):
bash-3.2$ ./check_erlang_application.sh -e erl -c cookie -n my_node@`hostname` -a kernel2
- CRITICAL - Application kernel2 not running on Node 'my_node@will-larsons-macbook.local'.
+ CRITICAL - Applications ["kernel2"] not running on Node 'my_node@will-larsons-macbook.local'.
bash-3.2$ ./check_erlang_application.sh -e erl -c cookie -n my_node@`hostname` -a kernel
- OK - Application kernel running on Node 'my_node@will-larsons-macbook.local'.
-
-Last, we can check on the process groups:
-
+ OK - Applications ["kernel"] running on Node 'my_node@will-larsons-macbook.local'.
And that is all there is to it.
View
96 check_erlang_application.sh
@@ -37,17 +37,20 @@ PROGNAME=`basename $0`
VERSION="Version 0.1,"
AUTHOR="2009, Will Larson [http://lethain.com]"
+RANDOM=`echo | awk '{srand(); print rand()}' | awk '{sub(/\./, ""); print}'` # $RANDOM for sh
+
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
-COOKIE="cookie" # cookie used by the local node
-NODE="node@localhost" # name of node to check
-TMP_NODE="nagios_check_app@`hostname`" # name of temporary node to ping $NODE
-ERL="/usr/bin/erl" # full path to erlang executable
-BEAM="`pwd`/ebin/" # full path to directory where nagios_erlang.beam exists
-VERBOSITY=0 # amount of detail to be returned, 0-3
-APPLICAITON="unknown" # name of application to check
+COOKIE="cookie" # cookie used by the local node
+NODE="node@localhost" # name of node to check
+TMP_NODE="nagios_check_app_$RANDOM" # name of temporary node to ping $NODE
+TMP_HOST="`hostname`"
+ERL="/usr/bin/erl" # full path to erlang executable
+BEAM="`pwd`/ebin/" # full path to directory where nagios_erlang.beam exists
+VERBOSITY=0 # amount of detail to be returned, 0-3
+APPLICAITON="unknown" # name of application to check
print_version() {
echo "$VERSION $AUTHOR"
@@ -66,6 +69,8 @@ print_help() {
echo " -n/--node : the node to ping against"
echo " -b/--beam : the absolute path to directory with nagios_erlang.beam"
echo " -c/--cookie : the cookie used by node (cookie)"
+ echo " -h/--help : show this screen"
+ echo " -H/--host : host of erlang node"
echo " -v/--verbosity : level of detail, 0-3 (0)"
echo " -V/--version : version of package"
echo " -h/--help : show this screen"
@@ -73,42 +78,51 @@ print_help() {
while test -n "$1"; do
case "$1" in
- --application|-a)
- APPLICATION=$2
- shift
- ;;
- --help|-h)
- print_help
- exit $ST_UK
- ;;
- --verbosity|-v)
- VERBOSITY=$2
- shift
- ;;
- --version|-V)
- print_version $PROGNAME $VERSION
- exit $ST_UK
- ;;
- --erl|-e)
- ERL=$2
- shift
- ;;
- --cookie|-c)
- COOKIE=$2
- shift
- ;;
- --node|-n)
- NODE=$2
- shift
- ;;
- *)
- echo "Uknown argument: $1"
- print_help
- exit $ST_UK
- ;;
- esac
+ --application|-a)
+ APPLICATION=$2
+ shift
+ ;;
+ --help|-h)
+ print_help
+ exit $ST_UK
+ ;;
+ --verbosity|-v)
+ VERBOSITY=$2
+ shift
+ ;;
+ --version|-V)
+ print_version $PROGNAME $VERSION
+ exit $ST_UK
+ ;;
+ --erl|-e)
+ ERL=$2
+ shift
+ ;;
+ --beam|-b)
+ BEAM=$2
+ shift
+ ;;
+ --cookie|-c)
+ COOKIE=$2
+ shift
+ ;;
+ --node|-n)
+ NODE=$2
+ shift
+ ;;
+ --host|-H)
+ TMP_HOST=$2
+ shift
+ ;;
+ *)
+ echo "Uknown argument: $1"
+ print_help
+ exit $ST_UK
+ ;;
+ esac
shift
done
+TMP_NODE="$TMP_NODE@$TMP_HOST"
CMD="$ERL -pa $BEAM -run nagios_erlang check_application $NODE $APPLICATION -noshell -name $TMP_NODE -setcookie $COOKIE"
if [ $VERBOSITY -ge 3 ]
then
View
88 check_erlang_node.sh
@@ -37,16 +37,19 @@ PROGNAME=`basename $0`
VERSION="Version 0.1,"
AUTHOR="2009, Will Larson [http://lethain.com]"
+RANDOM=`echo | awk '{srand(); print rand()}' | awk '{sub(/\./, ""); print}'` # $RANDOM for sh
+
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
-COOKIE="cookie" # cookie used by the local node
-NODE="node@localhost" # name of node to check
-TMP_NODE="nagios_check_node@`hostname`" # name of temporary node to ping $NODE
-ERL="/usr/bin/erl" # full path to erlang executable
-BEAM="`pwd`/ebin/" # full path to directory where nagios_erlang.beam exists
-VERBOSITY=0 # amount of detail to be returned, 0-3
+COOKIE="cookie" # cookie used by the local node
+NODE="node@localhost" # name of node to check
+TMP_NODE="nagios_check_node_$RANDOM" # name of temporary node to ping $NODE
+TMP_HOST="`hostname`"
+ERL="/usr/bin/erl" # full path to erlang executable
+BEAM="`pwd`/ebin/" # full path to directory where nagios_erlang.beam exists
+VERBOSITY=0 # amount of detail to be returned, 0-3
print_version() {
echo "$VERSION $AUTHOR"
@@ -71,42 +74,47 @@ print_help() {
while test -n "$1"; do
case "$1" in
- --help|-h)
- print_help
- exit $ST_UK
- ;;
- --verbosity|-v)
- VERBOSITY=$2
- shift
- ;;
- --version|-V)
- print_version $PROGNAME $VERSION
- exit $ST_UK
- ;;
- --erl|-e)
- ERL=$2
- shift
- ;;
- --beam|-b)
- BEAM=$2
- shift
- ;;
- --cookie|-c)
- COOKIE=$2
- shift
- ;;
- --node|-n)
- NODE=$2
- shift
- ;;
- *)
- echo "Uknown argument: $1"
- print_help
- exit $ST_UK
- ;;
- esac
+ --help|-h)
+ print_help
+ exit $ST_UK
+ ;;
+ --verbosity|-v)
+ VERBOSITY=$2
+ shift
+ ;;
+ --version|-V)
+ print_version $PROGNAME $VERSION
+ exit $ST_UK
+ ;;
+ --erl|-e)
+ ERL=$2
+ shift
+ ;;
+ --beam|-b)
+ BEAM=$2
+ shift
+ ;;
+ --cookie|-c)
+ COOKIE=$2
+ shift
+ ;;
+ --node|-n)
+ NODE=$2
+ shift
+ ;;
+ --host|-H)
+ TMP_HOST=$2
+ shift
+ ;;
+ *)
+ echo "Uknown argument: $1"
+ print_help
+ exit $ST_UK
+ ;;
+ esac
shift
done
+TMP_NODE="$TMP_NODE@$TMP_HOST"
CMD="$ERL -pa $BEAM -setcookie $COOKIE -run nagios_erlang check_node $NODE -noshell -name $TMP_NODE"
if [ $VERBOSITY -ge 3 ]
then
View
140 check_erlang_statistics.sh
@@ -0,0 +1,140 @@
+#!/bin/sh
+#
+# ## Overview
+#
+#
+#
+# ## Licence
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# ## Acknowledgements
+#
+# This script owes heavily to the [check_nginx.sh][cnsh] script, upon which the Bash components
+# are modeled.
+#
+# [cnsh]: http://exchange.nagios.org/directory/Plugins/Uncategorized/Software/check_nginx-2Esh/details "check_nginx.sh"
+#
+
+PROGNAME=`basename $0`
+VERSION="Version 0.1,"
+AUTHOR="2009, Will Larson [http://lethain.com]"
+
+RANDOM=`echo | awk '{srand(); print rand()}' | awk '{sub(/\./, ""); print}'` # $RANDOM for sh
+
+ST_OK=0
+ST_WR=1
+ST_CR=2
+ST_UK=3
+COOKIE="cookie" # cookie used by the local node
+NODE="node@localhost" # name of node to check
+TMP_NODE="nagios_check_app_$RANDOM" # name of temporary node to ping $NODE
+TMP_HOST="`hostname`"
+ERL="/usr/bin/erl" # full path to erlang executable
+BEAM="`pwd`/ebin/" # full path to directory where nagios_erlang.beam exists
+VERBOSITY=0 # amount of detail to be returned, 0-3
+APPLICAITON="unknown" # name of application to check
+ALIASES="undefined"
+
+print_version() {
+ echo "$VERSION $AUTHOR"
+}
+
+print_help() {
+ print_version $PROGNAME $VERSION
+ echo ""
+ echo "$PROGNAME is a Nagios plugin to check if an Erlang node is pingable from the local host."
+ echo ""
+ echo "$PROGNAME -e /usr/bin/erl -b /home/wl/nagios_erlang/ebin/ -n my_server -c my_cookie -p my_param1:100-200;myparam2:300-500 -a /path/to/add/stat/aliases"
+ echo ""
+ echo "Options:"
+ echo " -p/--parameters : parameters example 'sys_mem:50-100;total_process:300-500'"
+ echo " -a/--aliases : file with aliases in format {tag, Verbose, M,F,A}}"
+ echo " -e/--erl : the absolute path to erl binary (/usr/bin/erl)"
+ echo " -n/--node : the node to ping against"
+ echo " -b/--beam : the absolute path to directory with nagios_erlang.beam"
+ echo " -c/--cookie : the cookie used by node (cookie)"
+ echo " -v/--verbosity : level of detail, 0-3 (0)"
+ echo " -V/--version : version of package"
+ echo " -h/--help : show this screen"
+}
+
+while test -n "$1"; do
+ case "$1" in
+ --aliases|-a)
+ ALIASES=$2
+ shift
+ ;;
+ --parameters|-p)
+ PARAMETERS=$2
+ shift
+ ;;
+ --help|-h)
+ print_help
+ exit $ST_UK
+ ;;
+ --verbosity|-v)
+ VERBOSITY=$2
+ shift
+ ;;
+ --version|-V)
+ print_version $PROGNAME $VERSION
+ exit $ST_UK
+ ;;
+ --erl|-e)
+ ERL=$2
+ shift
+ ;;
+ --beam|-b)
+ BEAM=$2
+ shift
+ ;;
+ --cookie|-c)
+ COOKIE=$2
+ shift
+ ;;
+ --node|-n)
+ NODE=$2
+ shift
+ ;;
+ --host|-H)
+ TMP_HOST=$2
+ shift
+ ;;
+ *)
+ echo "Uknown argument: $1"
+ print_help
+ exit $ST_UK
+ ;;
+ esac
+ shift
+done
+TMP_NODE="$TMP_NODE@$TMP_HOST"
+CMD="$ERL -pa $BEAM -run nagios_erlang check_statistics $NODE $PARAMETERS $ALIASES -noshell -name $TMP_NODE -setcookie $COOKIE"
+if [ $VERBOSITY -ge 3 ]
+ then
+ echo "version: $VERSION"
+ echo "aliases: $ALIASES"
+ echo "parameters: $PARAMETERS"
+ echo "node: $NODE"
+ echo "cookie: $COOKIE"
+ echo "tmp_node: $TMP_NODE"
+ echo "erl: $ERL"
+ echo "beam: $BEAM"
+ echo "verbosity: $VERBOSITY"
+ echo "full command: $CMD"
+fi
+$CMD
+
View
235 nagios_erlang.erl
@@ -8,12 +8,15 @@
-module(nagios_erlang).
-author("Will Larson <lethain@gmail.com> [http://lethain.com]").
-version("0.1").
--export([check_process_group/1, check_node/1, check_application/1]).
+-export([check_process_group/1, check_node/1, check_application/1, check_statistics/1]).
-define(OK_CODE, 0).
-define(WARN_CODE, 1).
-define(CRIT_CODE, 2).
-define(UNKNOWN_CODE, 3).
-define(RPC_TIMEOUT, 1000).
+-define(STAT_ALIASES_FILE, "stat_aliases.cfg").
+
+-record(stat_state, {critical=[], warning=[], ok=[], aliases, level, memory}).
%%%
%%% External Interfaces
@@ -36,7 +39,7 @@ check_process_group([Node, Group, WarnLvl, CritLvl]) ->
%%
%% Has no return value due to calling erlang:halt/1.
%% @term check_node(atom()).
-check_node([Node]) ->
+check_node([Node]) ->
format_output(check_node_inner(Node)).
%% @doc Check if the specified application is currently running on the specified node,
@@ -44,8 +47,13 @@ check_node([Node]) ->
%%
%% Has no return value due to calling erlang:halt/1.
%% @spec check_application(atom(), atom().
-check_application([Node, Application]) ->
- format_output(check_application_inner(Node, Application)).
+check_application([Node, Applications]) ->
+ AppList = string:tokens(Applications, ","),
+ format_output(check_application_inner(Node, AppList)).
+
+check_statistics([Node, Params, AliasFile]) ->
+ ParamList = string:tokens(Params, ";"),
+ format_output(check_statistics_inner(Node, ParamList, AliasFile)).
%%%
%%% Internal Implementations
@@ -58,32 +66,44 @@ check_node_inner(Node) when is_list(Node) ->
check_node_inner(list_to_atom(Node));
check_node_inner(Node) ->
case net_adm:ping(Node) of
- pong ->
- {ok, "Node ~p running.~n", [Node]};
- pang ->
- {critical, "Node ~p not running.~n", [Node]}
+ pong ->
+ {ok, "Node ~p running.~n", [Node]};
+ pang ->
+ {critical, "Node ~p not running.~n", [Node]}
+ end.
+
+with_rpc(Node, M, F, A, SuccessHandler) ->
+ case rpc:call(Node, M, F, A, ?RPC_TIMEOUT) of
+ {badrpc, timeout} ->
+ {warning, "Node ~p did not respond within ~p milliseconds.~n", [Node, ?RPC_TIMEOUT]};
+ {badrpc, _} ->
+ {critical, "Couldn't contact Node ~p.~n", [Node]};
+ Resp ->
+ SuccessHandler(Resp)
end.
-
+
%% @doc Check that a remote node is running an application and return Nagios friendly response.
%% @spec check_application_inner(atom(), atom()) -> {status(), string(), list()}.
%% status = ok | warning | critical | unknown
-check_application_inner(Node, Application) when is_list(Node) ->
- check_application_inner(list_to_atom(Node), Application);
-check_application_inner(Node, Application) when is_list(Application) ->
- check_application_inner(Node, list_to_atom(Application));
-check_application_inner(Node, Application) ->
- case rpc:call(Node, application, start, [Application], ?RPC_TIMEOUT) of
- {badrpc, timeout} ->
- {warning, "Node ~p did not respond within ~p milliseconds.~n", [Node, ?RPC_TIMEOUT]};
- {badrpc, _} ->
- {critical, "Couldn't contact Node ~p.~n", [Node]};
- {error, {already_started, Application}} ->
- {ok, "Application ~p running on Node ~p.~n", [Application, Node]};
- %% @todo move the {application_started ???} -> critical, _Other -> unknown
- _Other ->
- {critical, "Application ~p not running on Node ~p.~n", [Application, Node]}
- end.
+check_application_inner(Node, CheckedApps) when is_list(Node) ->
+ check_application_inner(list_to_atom(Node), CheckedApps);
+check_application_inner(Node, CheckedApps) ->
+ with_rpc(Node, application, which_applications, [],
+ fun(ExistApps) ->
+ ExistNames = [atom_to_list(N) || {N, _, _} <- ExistApps],
+ BrokenApps = lists:filter(fun(A) ->
+ not lists:member(A, ExistNames)
+ end, CheckedApps),
+ case BrokenApps of
+ [] ->
+ {ok, "Applications ~p running on Node ~p.~n",
+ [CheckedApps, Node]};
+ _ ->
+ {critical, "Applications ~p not running on Node ~p.~n",
+ [BrokenApps, Node]}
+ end
+ end).
%% @doc Check status of a remote node's pg2 groups and return Nagios friendly response.
%% If WarnLvl is 0, then no warning messages will be sent.
@@ -100,43 +120,160 @@ check_process_group_inner(Node, Group, WarnLvl, CritLvl) when is_list(WarnLvl) -
check_process_group_inner(Node, Group, WarnLvl, CritLvl) when is_list(CritLvl) ->
check_process_group_inner(Node, Group, WarnLvl, list_to_integer(CritLvl));
check_process_group_inner(Node, Group, WarnLvl, CritLvl) ->
- case rpc:call(Node, pg2, get_members, [Group], ?RPC_TIMEOUT) of
+ with_rpc(Node, pg2, get_members, [Group],
+ fun(Resp) ->
+ case Resp of
+ {error,{no_such_group,Group}} ->
+ {critical, "Process Group ~p doesn't exist on Node ~p.~n", [Group, Node]};
+ Pids when is_list(Pids) ->
+ Length = length(Pids),
+ if Length < CritLvl -> {critical,
+ "Only ~p processes in Process Group ~p on Node ~p, expected ~p processes.",
+ [Length, Group, Node, CritLvl]};
+ Length < WarnLvl -> {warning,
+ "Only ~p processes in Process Group ~p on Node ~p, expected ~p processes.",
+ [Length, Group, Node, WarnLvl]};
+ true -> {ok,
+ "~p processes in Process Group ~p on Node ~p, meets expectation of ~p processes.",
+ [Length, Group, Node, WarnLvl]}
+ end;
+ _Other ->
+ {unknown, "Couldn't check Process Group ~p on Node ~p.~n", [Group, Node]}
+ end
+ end).
+
+check_statistics_inner(Node, Params, AliasFile) when is_list(Node) ->
+ check_statistics_inner(list_to_atom(Node), Params, AliasFile);
+
+check_statistics_inner(Node, Params, AliasFile) ->
+ Aliases = case file:consult(AliasFile) of
+ {error, _} -> undefined;
+ {ok, A} -> A
+ end,
+
+ Params2 = [string:tokens(P, ":") || P <- Params],
+ net_adm:ping(Node),
+ State3 = lists:foldl(
+ fun([P, R], State) ->
+ [W, E] = string:tokens(R, "-"),
+ Warn = list_to_integer(W),
+ Err = list_to_integer(E),
+ case check_one_param(Node, P, Warn, Err, State) of
+ {Res, State2} -> ok;
+ Res -> State2 = State
+ end,
+ case Res of
+ {critical, M, D} ->
+ State2#stat_state{critical=[{M, D}|State2#stat_state.critical]};
+ {warning, M, D} ->
+ State2#stat_state{warning=[{M, D}|State2#stat_state.critical]};
+ {ok, M, D} ->
+ State2#stat_state{ok=[{M, D}|State2#stat_state.critical]};
+ _ -> State2
+ end
+ end, #stat_state{aliases=Aliases}, Params2),
+ collect_state(State3).
+
+collect_messages(Messages) ->
+ lists:foldl(
+ fun({M, D}, {FM, FD}) ->
+ {M ++"; " ++ FM, D ++ FD}
+ end, {"", []}, Messages).
+
+collect_state(#stat_state{critical=Mess}) when Mess =/= [] ->
+ {M, D} = collect_messages(Mess),
+ {critical, M, D};
+collect_state(#stat_state{warning=Mess}) when Mess =/= [] ->
+ {M, D} = collect_messages(Mess),
+ {warning, M, D};
+collect_state(#stat_state{ok=Mess}) when Mess =/= [] ->
+ {M, D} = collect_messages(Mess),
+ {ok, M, D}.
+
+
+memory_key(Node, Key, #stat_state{memory=undefined}=State) ->
+ case rpc:call(Node, erlang, memory, [], ?RPC_TIMEOUT) of
{badrpc, timeout} ->
{warning, "Node ~p did not respond within ~p milliseconds.~n", [Node, ?RPC_TIMEOUT]};
{badrpc, _} ->
{critical, "Couldn't contact Node ~p.~n", [Node]};
- {error,{no_such_group,Group}} ->
- {critical, "Process Group ~p doesn't exist on Node ~p.~n", [Group, Node]};
- Pids when is_list(Pids) ->
- Length = length(Pids),
- if Length < CritLvl -> {critical, "Only ~p processes in Process Group ~p on Node ~p, expected ~p processes.", [Length, Group, Node, CritLvl]};
- Length < WarnLvl -> {warning, "Only ~p processes in Process Group ~p on Node ~p, expected ~p processes.", [Length, Group, Node, WarnLvl]};
- true -> {ok, "~p processes in Process Group ~p on Node ~p, meets expectation of ~p processes.", [Length, Group, Node, WarnLvl]}
- end;
- _Other ->
- {unknown, "Couldn't check Process Group ~p on Node ~p.~n", [Group, Node]}
- end.
+ Mem ->
+ memory_key(Node, Key, State#stat_state{memory=Mem})
+ end;
+memory_key(_Node, Key, #stat_state{memory=Mem}=State) ->
+ {ok, proplists:get_value(Key, Mem), State}.
+
+check_mem(Node, Key, Pref, Warn, Err, State) ->
+ case memory_key(Node, Key, State) of
+ {ok, Val, State2} ->
+ Res = check_val(trunc(Val/1000000), Warn, Err, Pref);
+ Res ->
+ State2 = State
+ end,
+ {Res, State2}.
+
+
+check_one_param(Node, "total_mem", Warn, Err, State) ->
+ check_mem(Node, total, "Total mem", Warn, Err, State);
+check_one_param(Node, "sys_mem", Warn, Err, State) ->
+ check_mem(Node, total, "Sys mem", Warn, Err, State);
+check_one_param(Node, "ets_mem", Warn, Err, State) ->
+ check_mem(Node, ets, "ETS mem", Warn, Err, State);
+check_one_param(Node, "proc_mem", Warn, Err, State) ->
+ check_mem(Node, processes, "Proc mem", Warn, Err, State);
+check_one_param(Node, "processes", Warn, Err, State) ->
+ with_rpc(Node, erlang, system_info, [process_count],
+ fun(Val) ->
+ {check_val(Val, Warn, Err, "Processes"), State}
+ end
+ );
+check_one_param(Node, "ports", Warn, Err, State) ->
+ with_rpc(Node, erlang, ports, [],
+ fun(Val) ->
+ {check_val(length(Val), Warn, Err, "Ports"), State}
+ end
+ );
+check_one_param(Node, Key, Warn, Err, #stat_state{aliases=Aliases}=State) when Aliases =/= undefined->
+ case lists:keyfind(Key, 1, Aliases) of
+ false -> {{critical, "Parameter " ++ Key ++"Not found", []}, State};
+ {Key, Pref, {M, F, A}} ->
+ with_rpc(Node, M, F, A,
+ fun(Val) ->
+ {check_val(Val, Warn, Err, Pref), State}
+ end
+ )
+ end;
+check_one_param(_Node, Key, _Warn, _Err, State)->
+ {{critical, "Parameter " ++ Key ++ "Not found", []}, State}.
+
+check_val(Val, _Warn, Err, Pref) when Val > Err ->
+ {critical, Pref ++ ": ~p > ~p", [Val, Err]};
+check_val(Val, Warn, _Err, Pref) when Val > Warn ->
+ {warning, Pref ++ ": ~p > ~p", [Val, Warn]};
+check_val(_Val, _Warn, _Err, Pref) ->
+ {ok, Pref, []}.
%%%
%%% Utilities
%%%
+
%% @doc Format input in the format expected by Nagios.
%% Status is used as exit code, and the formatted
%% combination of Msg & Vals is sent to stdout.
format_output({Status, Msg, Vals}) ->
case Status of
- ok ->
- io:format(lists:concat(["OK - ",Msg]), Vals),
- erlang:halt(?OK_CODE);
- warning ->
- io:format(lists:concat(["WARNING - ",Msg]), Vals),
- erlang:halt(?WARN_CODE);
- critical ->
- io:format(lists:concat(["CRITICAL - ",Msg]), Vals),
- erlang:halt(?CRIT_CODE);
- unknown ->
- io:format(lists:concat(["UNKNOWN - ",Msg]), Vals),
- erlang:halt(?UNKNOWN_CODE)
+ ok ->
+ io:format(lists:concat(["OK - ",Msg]), Vals),
+ erlang:halt(?OK_CODE);
+ warning ->
+ io:format(lists:concat(["WARNING - ",Msg]), Vals),
+ erlang:halt(?WARN_CODE);
+ critical ->
+ io:format(lists:concat(["CRITICAL - ",Msg]), Vals),
+ erlang:halt(?CRIT_CODE);
+ unknown ->
+ io:format(lists:concat(["UNKNOWN - ",Msg]), Vals),
+ erlang:halt(?UNKNOWN_CODE)
end.
Something went wrong with that request. Please try again.