diff --git a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ new file mode 100755 index 00000000..43d6ed27 --- /dev/null +++ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ @@ -0,0 +1,231 @@ +#!/usr/bin/env bash + +# ejabberd_resources_ revision 3 (Nov 2013) +# +# Tested with ejabberd 2.1.x +# +# This plugin is capable to show: +# - ejabberd memory usage (RSS, VSZ, erlang internal) +# - ejabberd ports/processes usage +# - online/registered users by vhost +# +# Required permissions: +# - read ejabberdctl configuration file +# - connect to a running ejabberd node +# +# OS: *NIX +# +# Author: Artem Sheremet +# +# 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 + +#%# family=auto +#%# capabilities=autoconf suggest + +EJABBERDCTL_CFG=${ejabberdctl_cfg:-/etc/ejabberd/ejabberdctl.cfg} +source $EJABBERDCTL_CFG 2>/dev/null +source $MUNIN_LIBDIR/plugins/plugin.sh + +ERLANG_HOST=${ERLANG_NODE/*@/} +ERLANG_MUNIN_NODE=munin + +ERL=${erl_path:-$(which erl)} + +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 +} + +SCRIPT_NAME=$(basename $0) +RESOURCE_TYPE="${SCRIPT_NAME/ejabberd_resources_/}" +RESOURCE_BASE=1000 +[ "$RESOURCE_TYPE" = "memory" ] && RESOURCE_BASE=1024 + +function hosts_list() { + ejabberd_exec 'ejabberd_config:get_global_option(hosts).' | tr '[]",' ' ' +} + +function ejabberd_report_online_users() { + [ "$1" = "config" ] && echo 'graph_vlabel users' + for host in $(hosts_list); do + local clean_host=$(clean_fieldname $host) + local ejabberd_command="length(ejabberd_sm:get_vh_session_list(\"$host\"))" + if [ "$1" = "config" ]; then + cat <