From 85072bf99d1a15181fc08ce7e6f83d0cbc96acee Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Wed, 4 Feb 2015 15:37:56 +0100 Subject: [PATCH 1/3] Update ejabberd_resources_* to use erl_call --- .../ejabberd_resources_/ejabberd_resources_ | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ index ae16d4a5..57394510 100755 --- a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ +++ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ @@ -21,7 +21,7 @@ # Configuration: # - set env.ejabberdctl_cfg to ejabberdctl.cfg path if necessary # - or set env.ERLANG_NODE, env.EJABBERD_PID_PATH to proper values manually -# - set erl_path to unregular erlang interpreter cli location +# - set erl_call_path to unregular erl_call location #%# family=auto #%# capabilities=autoconf suggest @@ -33,22 +33,14 @@ source $MUNIN_LIBDIR/plugins/plugin.sh ERLANG_HOST=${ERLANG_NODE/*@/} ERLANG_MUNIN_NODE=munin -ERL=${erl_path:-$(which erl)} +if [ -n "$erl_path" ] && [ -z "$erl_call_path" ]; then + erl_call_path="$erl_path"_call +fi + +ERL_CALL=${erl_call_path:-$(which erl_call)} function ejabberd_exec() { - COMMAND=${1//\"/\\\"} - su - ejabberd $ERL -noinput \ - -sname $ERLANG_MUNIN_NODE@$ERLANG_HOST \ - -noinput \ - -hidden \ - -eval "try {ok,S,_} = erl_scan:string(\"$COMMAND\"), - {ok,P} = erl_parse:parse_exprs(S), - {value,V,_} = rpc:call('$ERLANG_NODE', erl_eval, exprs, [P,[]]), - io:format(\"~p\n\", [V]) - catch - _:Err -> io:format(\"~p\n\", [Err]) - end." \ - -s init stop + echo "$1" | su - ejabberd -c "$ERL_CALL -e -n $ERLANG_NODE" | sed -re 's/^\{ok, (.*)\}$/\1/' } SCRIPT_NAME=$(basename $0) @@ -94,6 +86,7 @@ CONFIG done } + function ejabberd_report_memory() { if [ "$1" = "config" ]; then cat < Date: Mon, 9 Mar 2015 10:33:42 +0100 Subject: [PATCH 2/3] ejabberd_resources: add mnesia table info support --- .../ejabberd_resources_/ejabberd_resources_ | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ index 57394510..4621a5e7 100755 --- a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ +++ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# ejabberd_resources_ revision 3 (Nov 2013) +# ejabberd_resources_ revision 4 (Mar 2015) # # Tested with ejabberd 2.1.x # @@ -8,6 +8,7 @@ # - ejabberd memory usage (RSS, VSZ, erlang internal) # - ejabberd ports/processes usage # - online/registered users by vhost +# - mnesia table sizes and location # # Required permissions: # - read ejabberdctl configuration file @@ -19,9 +20,10 @@ # Author: Artem Sheremet # # Configuration: -# - set env.ejabberdctl_cfg to ejabberdctl.cfg path if necessary +# - set env.ejabberdctl_cfg to ejabberdctl.cfg path if not in /etc # - or set env.ERLANG_NODE, env.EJABBERD_PID_PATH to proper values manually # - set erl_call_path to unregular erl_call location +# - set env.ejabberdctl to ejabberdctl script path if not on PATH #%# family=auto #%# capabilities=autoconf suggest @@ -30,6 +32,8 @@ EJABBERDCTL_CFG=${ejabberdctl_cfg:-/etc/ejabberd/ejabberdctl.cfg} source $EJABBERDCTL_CFG 2>/dev/null source $MUNIN_LIBDIR/plugins/plugin.sh +EJABBERDCTL=${ejabberdctl:-$(which ejabberdctl)} + ERLANG_HOST=${ERLANG_NODE/*@/} ERLANG_MUNIN_NODE=munin @@ -155,6 +159,53 @@ DATA fi } +function ejabberd_report_mnesia() { + local draw sed_re long_bits + + sed_re='([a-z_]+) *: with ([0-9]+) +records occupying ([0-9]+) +([a-z]+) o[fn] ([a-z]+)' + # 1 = table_name + # 2 = records number + # 3 = bytes/words number + # 4 = unit (bytes or words) + # 5 = storage (disc or mem) + + if [ "$1" = config ]; then + echo "graph_vlabel $2" + draw=LINE2 + [ "$2" = bytes ] && draw=AREASTACK + + $EJABBERDCTL mnesia info | sed -re 's/'"$sed_re"'/\1 \5/;tx;d;:x' | + while read table_name table_storage; do + echo "${table_name}_${table_storage}.draw $draw" + echo "${table_name}_${table_storage}.label $table_name ($table_storage)" + done + else + if [ "$2" = recs ]; then + $EJABBERDCTL mnesia info | sed -re 's/'"$sed_re"'/\1_\5.value \2/;tx;d;:x' + else + long_bits=$(getconf LONG_BIT) + $EJABBERDCTL mnesia info | + sed -re 's/'"$sed_re"'/\1_\5.value \3 \4/;tx;d;:x' | + awk " + / words\$/ { + print \$1, \$2 * $long_bits / 8 + } + / bytes\$/ { + print \$1, \$2 + } + " + fi + fi +} + +function ejabberd_report_mnesia_bytes() { + ejabberd_report_mnesia "$1" bytes +} + +function ejabberd_report_mnesia_recs() { + ejabberd_report_mnesia "$1" recs +} + function open_files_counter_util() { if hash lsof &>/dev/null; then echo lsof @@ -232,6 +283,8 @@ processes ports online_users registered_users +mnesia_recs +mnesia_bytes SUGGESTIONS open_files_counter_util &>/dev/null && echo open_files exit 0 From 01ae710b24ccdf598234c0ff51c08272ac3f8c1e Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Mon, 9 Mar 2015 10:24:36 +0100 Subject: [PATCH 3/3] Fix logic of ping plugin default behavior (-w 2) --- plugins/network/ping/ping | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/network/ping/ping b/plugins/network/ping/ping index 858fb6d3..3495dd77 100755 --- a/plugins/network/ping/ping +++ b/plugins/network/ping/ping @@ -70,7 +70,9 @@ use Munin::Plugin; my $ping = exists $ENV{ping} ? $ENV{ping} : "ping"; my $ping6 = exists $ENV{ping6} ? $ENV{ping6} : "ping6"; -my $ping_args = exists $ENV{ping_args} ? $ENV{ping_args} : "-c 2 -w 1"; +# Since ping sends a packet every second (-i 1) by default, +# we may need 2 total seconds (-w 2) for <1000msec replies +my $ping_args = exists $ENV{ping_args} ? $ENV{ping_args} : "-c 2 -w 2"; my $ping_args2 = exists $ENV{ping_args2} ? $ENV{ping_args2} : ""; my $fork = exists $ENV{fork} ? $ENV{fork} : 0; my $packetloss_mode = ($0 =~ /_packetloss$/);