#!/usr/bin/env bash # 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 # - mnesia table sizes and location # # Required permissions: # - read ejabberdctl configuration file # - connect to a running ejabberd node # # OS: *NIX # Requires lsof/fstat for open_files. # # Author: Artem Sheremet # # Configuration: # - 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 EJABBERDCTL_CFG=${ejabberdctl_cfg:-/etc/ejabberd/ejabberdctl.cfg} . "$EJABBERDCTL_CFG" 2>/dev/null . "$MUNIN_LIBDIR/plugins/plugin.sh" EJABBERDCTL=${ejabberdctl:-$(which ejabberdctl)} ERLANG_HOST=${ERLANG_NODE/*@/} ERLANG_MUNIN_NODE=munin 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() { echo "$1" | su - ejabberd -c "$ERL_CALL -e -n $ERLANG_NODE" | sed -re 's/^\{ok, (.*)\}$/\1/' } 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 local ejabberd_command clean_host=$(clean_fieldname "$host") ejabberd_command="length(ejabberd_sm:get_vh_session_list(\"$host\"))" if [ "$1" = "config" ]; then cat < case whereis(Name) of Pid when is_pid(Pid) -> {links, Links} = erlang:process_info(Pid, links), {true, {Name, length(Links)}}; _ -> false end, registered())" } function open_files_counter_util() { if hash lsof &>/dev/null; then echo lsof return 0 elif hash fstat &>/dev/null; then echo fstat return 0 fi return 1 } function open_files_number() { echo "$(( $("$(open_files_counter_util)" -np "$(<"$EJABBERD_PID_PATH")" | wc -l) - 1))" } function ejabberd_report_open_files() { # this spawns a child process, but in most cases the open files limit is inherited local limit limit=$(ejabberd_exec 'os:cmd("ulimit -n").' | tr '"\\n' ' ') if [ "$1" = "config" ]; then cat </dev/null && echo open_files exit 0 ;; config) cat <