1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 18:38:30 +00:00

Fixed some minor-bugs. Corrected formatting and better coments in the code.

This commit is contained in:
Peter Viskup 2010-11-15 22:13:54 +01:00 committed by Steve Schnepp
parent a345d90e2f
commit ebf1e5f0b8

View file

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# Munin plugin for ejabberd2. # Munin plugin for ejabberd2.
# This script supports versions 2.0 and 2.1 of ejabberd.
# #
# Written by Lasse Karstensen <lkarsten@hyse.org> 2007-05-27. # Written by Lasse Karstensen <lkarsten@hyse.org> 2007-05-27.
# Based on ejabberd-plugin by Christian Dröge <Christian@draugr.de> # Based on ejabberd-plugin by Christian Dröge <Christian@draugr.de>
@ -18,33 +19,33 @@
# ejabberd_statuses # ejabberd_statuses
# ejabberd_memory # ejabberd_memory
# ejabberd_threads # ejabberd_threads
# ejabberd_userindays # ejabberd_usersindays
# ejabberd_uptime # ejabberd_uptime
# #
# use ln -s ejabberd ejabberd_(connections|users|registrations) # use ln -s ejabberd ejabberd_(connections|users|registrations|statuses|memory|threads|usersindays|uptime)
# to activate. # to activate.
# #
# If the autodetect-feature for vhosts breaks, you can set # If the autodetect-feature for vhosts breaks, you can set
# """ # """
# [ejabberd*] # [ejabberd*]
# env.vhosts foo.com bar.com # env.vhosts foo.com bar.com
# env.statuses available away chat xa # monitoring of statuses
# env.days 1 7 30 # monitoring for usersindays
# user ejabberd # user ejabberd should have enough priviledges
# # depends on your setup
# """ # """
# in plugin-conf.d/munin-node to override it. # in plugin-conf.d/munin-node to override it.
# (user root may also be smart/not so smart depending on your setup.)
# #
#%# family=auto #%# family=auto
#%# capabilities=autoconf suggest #%# capabilities=autoconf suggest
EJCTL=$(which ejabberdctl) EJCTL=$(which ejabberdctl)
# Add munin argument to ejabberdctl to prevent a lot of ejabberdctl
# records in memory see discussion:
# http://lists.jabber.ru/pipermail/ejabberd/2009-September/005337.html
EJVER=$($EJCTL status | awk '/^ejabberd / {print $2}') EJVER=$($EJCTL status | awk '/^ejabberd / {print $2}')
if [ "$1" == "autoconf" ]; then if [ "$1" == "autoconf" ]; then
if [ -x $EJCTL > /dev/null ]; then if [ -x $EJCTL > /dev/null ]; then
echo yes echo yes
exit 0 exit 0
fi fi
echo "no (ejabberdctl not found)" echo "no (ejabberdctl not found)"
exit 1 exit 1
@ -62,26 +63,50 @@ if [ "$1" == "suggest" ]; then
exit 0 exit 0
fi fi
# Add munin argument to ejabberdctl to prevent a lot of ejabberdctl
# records in memory see discussion:
# http://lists.jabber.ru/pipermail/ejabberd/2009-September/005337.html
# Add these lines to ejabberdctl script to get it work
#@@ -56,6 +56,15 @@
# $KERNEL_OPTS \
# "$@"
# ;;
#+ munin)
#+ shift
#+ exec $ERL $SNAME ejabberdctlmunin \
#+ -pa $EBIN_DIR \
#+ -s ejabberd_ctl \
#+ -noinput \
#+ $KERNEL_OPTS \
#+ -extra $ERLANG_NODE "$@"
#+ ;;
# *)
# exec $ERL $SNAME ejabberdctl$SUFFIX \
# -pa $EBIN_DIR \
#
# Or just comment out following line
EJCTL="$EJCTL munin"
# trying to autodetect running vhosts. # trying to autodetect running vhosts.
if [ -z "$vhosts" ]; then if [ -z "$vhosts" ]; then
for CFGPATH in /etc/ejabberd /usr/local/ejabberd/etc; do for CFGPATH in /etc/ejabberd /usr/local/ejabberd/etc; do
if [ -f "$CFGPATH/ejabberd.cfg" ]; then if [ -f "$CFGPATH/ejabberd.cfg" ]; then
EJCFG=$CFGPATH/ejabberd.cfg; EJCFG=$CFGPATH/ejabberd.cfg
fi fi
done done
if [ -z "$EJCFG" ]; then if [ -z "$EJCFG" ]; then
echo "Unable to find ejabberd.cfg. Exiting." > /dev/stderr echo "Unable to find ejabberd.cfg. Exiting." > /dev/stderr
exit -1 exit -1
fi fi
# you have to have all of vhosts defined on one line in $EJCFG or in plugins-conf.d/munin-node config file # you have to have all of vhosts defined on one line in $EJCFG or in plugins-conf.d/munin-node config file
vhosts=$(awk '/^\s*{hosts/ {gsub( /\{\s?hosts\s?,|[\",\[\]]|\}\s?.|localhost/ ,""); print;}' $EJCFG); vhosts=$(awk '/^\s*{hosts/ {gsub( /\{\s?hosts\s?,|[\",\[\]]|\}\s?.|localhost/ ,""); print;}' $EJCFG)
fi fi
# get ejabberd PID # get ejabberd PID
if [[ ${EJVER%\.[0-9]} == 2.1 ]]; then if [[ ${EJVER%\.[0-9]} == 2.1 ]]; then
EJPID=$(cat /var/run/ejabberd/ejabberd.pid) EJPID=$(cat /var/run/ejabberd/ejabberd.pid)
else else
EJPID=$(ps -ef | awk '/\/bin\/beam.smp/ && !/awk/ {print $2}') EJPID=$(ps -ef | awk '/\/bin\/beam.smp/ && !/awk/ {print $2}')
fi fi
if [ -z "$vhosts" ]; then if [ -z "$vhosts" ]; then
@ -90,207 +115,175 @@ if [ -z "$vhosts" ]; then
exit -1 exit -1
fi fi
MODE=`basename $0 | sed 's/^ejabberd_//g'` MODE=$(basename $0 | sed 's/^ejabberd_//g')
if ! [ "$MODE" == "connections" -o "$MODE" == "users" \ if ! [ "$MODE" == "connections" -o "$MODE" == "users" \
-o "$MODE" == "registrations" -o "$MODE" == "statuses" \ -o "$MODE" == "registrations" -o "$MODE" == "statuses" \
-o "$MODE" == "memory" -o "$MODE" == "threads" \ -o "$MODE" == "memory" -o "$MODE" == "threads" \
-o "$MODE" == "usersindays" -o "$MODE" == "uptime" ]; then -o "$MODE" == "usersindays" -o "$MODE" == "uptime" ]; then
echo "ERROR: Unknown mode \"$MODE\". Exiting." > /dev/stderr echo "ERROR: Unknown mode \"$MODE\". Exiting." > /dev/stderr
exit -1 exit -1
else
# EJCTL="$EJCTL munin$MODE"
EJCTL="$EJCTL munin"
fi fi
if [ "$1" = "config" ]; then if [ "$1" = "config" ]; then
if [ "$MODE" == "memory" ]; then
echo 'graph_args --base 1024 -l 0'
echo 'graph_scale yes'
echo 'graph_category ejabberd'
echo 'graph_info This graph shows a statistic of ejabberd'
echo 'graph_title Memory of ejabberd process'
echo 'graph_vlabel Bytes'
echo "ejabberd_memory_size.label actual memory";
echo "ejabberd_memory_size.info Memory used by ejabberd process in Bytes";
echo "ejabberd_memory_peak.label memory peak";
echo "ejabberd_memory_peak.info Memory peak of ejabberd process in Bytes";
else
echo 'graph_args --base 1000 -l 0'
echo 'graph_scale no'
echo 'graph_category ejabberd' echo 'graph_category ejabberd'
echo 'graph_info This graph shows a statistic of ejabberd' echo 'graph_info This graph shows statistics of ejabberd server'
if [ "$MODE" == "memory" ]; then
if [ "$MODE" == "connections" ]; then echo 'graph_args --base 1024 -l 0'
echo 'graph_title ejabberd server-to-server conections' echo 'graph_scale yes'
echo 'graph_vlabel s2s' echo 'graph_title Memory usage'
echo 's2s_connections_out.label incoming s2s connections' echo 'graph_vlabel Bytes'
echo 's2s_connections_out.info Number of outgoing server to server connections' echo "ejabberd_memory_size.label actual memory"
echo 's2s_connections_in.label outgoing s2s connections' echo "ejabberd_memory_size.info Memory used by ejabberd process in Bytes"
echo 's2s_connections_in.info Number of incoming server to server connections' echo "ejabberd_memory_peak.label memory peak"
elif [ "$MODE" == "users" ]; then echo "ejabberd_memory_peak.info Memory peak of ejabberd process in Bytes"
echo 'graph_title ejabberd connected users' else
echo 'graph_vlabel users' echo 'graph_args --base 1000 -l 0'
for host in $vhosts; do echo 'graph_scale no'
formathost=$(echo $host | tr '.' '_') if [ "$MODE" == "connections" ]; then
echo "connected_users_$formathost.label $host connected users"; echo 'graph_title Server-to-server conections'
echo "connected_unique_users_$formathost.label $host unique connected users"; echo 'graph_vlabel connections'
done; echo 's2s_connections_out.label outgoing s2s connections'
elif [ "$MODE" == "registrations" ]; then echo 's2s_connections_out.info Number of outgoing server to server connections'
echo 'graph_title ejabberd registrations' echo 's2s_connections_in.label incoming s2s connections'
echo 'graph_vlabel users' echo 's2s_connections_in.info Number of incoming server to server connections'
for host in $vhosts; do elif [ "$MODE" == "users" ]; then
formathost=$(echo $host | tr '.' '_') echo 'graph_title Connected users'
echo "registered_$formathost.label $host registered users"; echo 'graph_vlabel users'
echo "registered_$formathost.info Registered users for vhost $host" for host in $vhosts; do
done; formathost=$(echo $host | tr '.' '_')
elif [ "$MODE" == "statuses" ]; then echo "connected_users_$formathost.label $host connected users"
echo 'graph_title users with statuses' echo "connected_unique_users_$formathost.label $host unique connected users"
echo 'graph_vlabel users' done
for host in $vhosts; do elif [ "$MODE" == "registrations" ]; then
for status in $statuses; do echo 'graph_title User registrations'
formathost=$(echo $host | tr '.' '_') echo 'graph_vlabel users'
echo "status_${formathost}_${status}.label $status on $host"; for host in $vhosts; do
echo "status_${formathost}_${status}.info Users with status $status on $host [xa=not available, dnd=(do not disturb) or (busy), chat=free for chat]"; formathost=$(echo $host | tr '.' '_')
done; echo "registered_$formathost.label $host registered users"
done; echo "registered_$formathost.info Registered users for vhost $host"
elif [ "$MODE" == "threads" ]; then done
echo 'graph_title Threads of ejabberd process' elif [ "$MODE" == "statuses" ]; then
echo 'graph_vlabel threads' echo 'graph_title User statuses'
echo "ejabberd_threads.label number of threads"; echo 'graph_vlabel users'
echo "ejabberd_threads.info Number of threads of ejabberd process"; for host in $vhosts; do
elif [ "$MODE" == "usersindays" ]; then for status in $statuses; do
echo 'graph_title Active users in last days' formathost=$(echo $host | tr '.' '_')
echo 'graph_vlabel users' echo "status_${formathost}_${status}.label $status on $host"
for host in $vhosts; do echo "status_${formathost}_${status}.info Users with status $status on $host [xa=not available, dnd=(do not disturb) or (busy), chat=free for chat]"
for num in $days; do done
formathost=$(echo $host | tr '.' '_') done
echo "usersindays_${formathost}_${num}.label active users on $host in last $num days"; elif [ "$MODE" == "threads" ]; then
echo "usersindays_${formathost}_${num}.info Number of users active on $host in last $num days"; echo 'graph_title Threads'
done; echo 'graph_vlabel threads'
done; echo "ejabberd_threads.label number of threads"
elif [ "$MODE" == "uptime" ]; then echo "ejabberd_threads.info Number of threads of ejabberd process"
echo 'graph_title Uptime of ejabberd server' elif [ "$MODE" == "usersindays" ]; then
echo 'uptime in days' echo 'graph_title Active users'
echo "uptime.label uptime" echo 'graph_vlabel users'
echo 'uptime.draw AREA' for host in $vhosts; do
for num in $days; do
formathost=$(echo $host | tr '.' '_')
echo "usersindays_${formathost}_${num}.label $host active users [$num days]"
echo "usersindays_${formathost}_${num}.info Number of $host users active in last $num days"
done
done
elif [ "$MODE" == "uptime" ]; then
echo 'graph_title Uptime'
echo 'graph_vlabel days'
echo "uptime.label uptime"
echo 'uptime.draw AREA'
fi
fi fi
fi
exit 0
fi
if [ "$MODE" == "connections" ]; then
echo "s2s_connections_out.value $($EJCTL outgoing_s2s_number)"
echo "s2s_connections_in.value $($EJCTL incoming_s2s_number)"
exit 0 exit 0
fi fi
if [[ ${EJVER%\.[0-9]} == 2.1 ]]; then if [[ ${EJVER%\.[0-9]} == 2.1 ]]; then
if [ "$MODE" == "users" ]; then if [ "$MODE" == "users" ]; then
for host in $vhosts; do for host in $vhosts; do
formathost=$(echo $host | tr '.' '_') formathost=$(echo $host | tr '.' '_')
echo "connected_users_$formathost.value $($EJCTL stats_host onlineusers $host)"; echo "connected_users_$formathost.value $($EJCTL stats_host onlineusers $host)"
echo "connected_unique_users_$formathost.value $($EJCTL connected_users_vhost $host | awk -v var=$host -F/ '{users[$1]} END {for (user in users) {if (index(user,var)) {count++}} print count}')"; echo "connected_unique_users_$formathost.value $($EJCTL connected_users_vhost $host | awk -v var=$host -F/ '{users[$1]} END {for (user in users) {if (index(user,var)) {count++}} print count}')"
done done
exit 0 elif [ "$MODE" == "registrations" ]; then
fi for host in $vhosts; do
formathost=$(echo $host | tr '.' '_')
if [ "$MODE" == "registrations" ]; then num=$($EJCTL stats_host registeredusers $host)
for host in $vhosts; do if [ "$?" != 0 ]; then
formathost=$(echo $host | tr '.' '_') num="U"
num=$($EJCTL stats_host registeredusers $host) fi
if [ "$?" != 0 ]; then echo "registered_$formathost.value $num"
num="U" done
fi elif [ "$MODE" == "statuses" ]; then
echo "registered_$formathost.value $num"; for host in $vhosts; do
done formathost=$(echo $host | tr '.' '_')
exit 0 for status in $statuses; do
fi num=$($EJCTL status_num_host $host $status)
if [ "$?" != 0 ]; then
if [ "$MODE" == "statuses" ]; then num="U"
for host in $vhosts; do fi
formathost=$(echo $host | tr '.' '_') echo "status_${formathost}_${status}.value $num"
for status in $statuses; do done
num=$($EJCTL status_num_host $host $status) done
if [ "$?" != 0 ]; then elif [ "$MODE" == "usersindays" ]; then
num="U" for host in $vhosts; do
fi for num in $days; do
echo "status_${formathost}_${status}.value $num"; formathost=$(echo $host | tr '.' '_')
done echo "usersindays_${formathost}_${num}.value $($EJCTL num_active_users $host $num)"
done done
exit 0 done
fi elif [ "$MODE" == "uptime" ]; then
echo "uptime.value $($EJCTL stats uptimeseconds | awk '{printf "%.2f", $1/86400}')"
if [ "$MODE" == "usersindays" ]; then elif [ "$MODE" == "connections" ]; then
for host in $vhosts; do echo "s2s_connections_out.value $($EJCTL outgoing_s2s_number)"
for num in $days; do echo "s2s_connections_in.value $($EJCTL incoming_s2s_number)"
formathost=$(echo $host | tr '.' '_') fi
echo "usersindays_${formathost}_${num}.value $($EJCTL num_active_users $host $num)";
done;
done;
exit 0
fi
if [ "$MODE" == "uptime" ]; then
echo "uptime.value $($EJCTL stats uptimeseconds | awk '{printf "%.2f", $1/86400}')"
fi
elif [[ ${EJVER%\.[0-9]} == 2.0 ]]; then elif [[ ${EJVER%\.[0-9]} == 2.0 ]]; then
if [ "$MODE" == "users" ]; then if [ "$MODE" == "users" ]; then
for host in $vhosts; do for host in $vhosts; do
formathost=$(echo $host | tr '.' '_') formathost=$(echo $host | tr '.' '_')
echo "connected_users_$formathost.value $($EJCTL vhost $host stats onlineusers)"; echo "connected_users_$formathost.value $($EJCTL vhost $host stats onlineusers)"
echo "connected_unique_users_$formathost.value $($EJCTL connected-users | awk -v var=$host -F/ '{users[$1]} END {for (user in users) {if (index(user,var)) {count++}} print count}')"; echo "connected_unique_users_$formathost.value $($EJCTL connected-users | awk -v var=$host -F/ '{users[$1]} END {for (user in users) {if (index(user,var)) {count++}} print count}')"
done done
exit 0 elif [ "$MODE" == "registrations" ]; then
fi for host in $vhosts; do
formathost=$(echo $host | tr '.' '_')
if [ "$MODE" == "registrations" ]; then num=$($EJCTL vhost $host stats registeredusers)
for host in $vhosts; do if [ "$?" != 0 ]; then
formathost=$(echo $host | tr '.' '_') num="U"
num=$($EJCTL vhost $host stats registeredusers) fi
if [ "$?" != 0 ]; then echo "registered_$formathost.value $num"
num="U" done
fi elif [ "$MODE" == "statuses" ]; then
echo "registered_$formathost.value $num" for host in $vhosts; do
done formathost=$(echo $host | tr '.' '_')
exit 0 for status in $statuses; do
fi num=$($EJCTL vhost $host status-num $status)
if [ "$?" != 0 ]; then
if [ "$MODE" == "statuses" ]; then num="U"
for host in $vhosts; do fi
formathost=$(echo $host | tr '.' '_') echo "status_${formathost}_${status}.value $num"
for status in $statuses; do done
num=$($EJCTL vhost $host status-num $status) done
if [ "$?" != 0 ]; then elif [ "$MODE" == "usersindays" ]; then
num="U" for host in $vhosts; do
fi for num in $days; do
echo "status_${formathost}_${status}.value $num"; formathost=$(echo $host | tr '.' '_')
done echo "usersindays_${formathost}_${num}.value $($EJCTL vhost $host num-active-users $num)"
done done
exit 0 done
fi elif [ "$MODE" == "uptime" ]; then
echo "uptime.value $($EJCTL stats uptime-seconds | awk '{printf "%.2f", $1/86400}')"
if [ "$MODE" == "usersindays" ]; then elif [ "$MODE" == "connections" ]; then
for host in $vhosts; do echo "s2s_connections_out.value $($EJCTL outgoing-s2s-number)"
for num in $days; do echo "s2s_connections_in.value $($EJCTL incoming-s2s-number)"
formathost=$(echo $host | tr '.' '_') fi
echo "usersindays_${formathost}_${num}.value $($EJCTL vhost $host num-active-users $num)";
done;
done;
exit 0
fi
if [ "$MODE" == "uptime" ]; then
echo "uptime.value $($EJCTL stats uptime-seconds | awk '{printf "%.2f", $1/86400}')"
fi
fi fi
if [ "$MODE" == "memory" ]; then if [ "$MODE" == "memory" ]; then
echo "ejabberd_memory_size.value $(awk '/VmSize/ {print $2*1024}' /proc/${EJPID}/status)" echo "ejabberd_memory_size.value $(awk '/VmSize/ {print $2*1024}' /proc/${EJPID}/status)"
echo "ejabberd_memory_peak.value $(awk '/VmPeak/ {print $2*1024}' /proc/${EJPID}/status)" echo "ejabberd_memory_peak.value $(awk '/VmPeak/ {print $2*1024}' /proc/${EJPID}/status)"
exit 0 elif [ "$MODE" == "threads" ]; then
fi
if [ "$MODE" == "threads" ]; then
echo "ejabberd_threads.value $(awk '/Threads/ {print $2}' /proc/${EJPID}/status)" echo "ejabberd_threads.value $(awk '/Threads/ {print $2}' /proc/${EJPID}/status)"
exit 0
fi fi
exit 0