From 0ae7b31a7b6c8df66293310fbbc0755a233475a7 Mon Sep 17 00:00:00 2001 From: Peter Viskup Date: Sun, 27 May 2007 21:34:15 +0200 Subject: [PATCH] Initial version --- plugins/other/ejabberd_ | 250 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100755 plugins/other/ejabberd_ diff --git a/plugins/other/ejabberd_ b/plugins/other/ejabberd_ new file mode 100755 index 00000000..6c213482 --- /dev/null +++ b/plugins/other/ejabberd_ @@ -0,0 +1,250 @@ +#!/bin/bash +# +# Munin plugin for ejabberd2. +# +# Written by Lasse Karstensen 2007-05-27. +# Based on ejabberd-plugin by Christian Dröge +# +# Status, memory, threads, uptime, usersindays, ejabberd2 and other code +# optimisation by Peter Viskup +# +# As connected users, registered users and server-connections have somewhat +# different scales, this plugin uses munins suggest feature to create three +# different graphs. +# +# ejabberd_connections +# ejabberd_users +# ejabberd_registrations +# ejabberd_statuses +# ejabberd_memory +# ejabberd_threads +# ejabberd_usersindays +# ejabberd_uptime +# +# use command +# ln -s ejabberd_ ejabberd_(connections|memory|registrations|statuses|threads|uptime|users|usersindays) +# to activate. +# +# If the autodetect-feature for vhosts breaks, you can set +# """ +# [ejabberd_*] +# env.vhosts foo.com bar.com +# """ +# in plugin-conf.d/munin-node to override it. +# (user root may also be smart/not so smart depending on your setup.) +# Be aware that datasource name of rrdtool is restricted to 19 characters maximum. It could lead to not working plugin if vhost string is too long. +# http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html +# +# For monitoring user statuses - define statuses environment variable: +# (you can monitor only some of them) +# [ejabberd_*] +# env.statuses available away chat xa +# +# For usersindays statistics define days environment variable +# Be careful on high loaded servers, because it will plot all days in one +# graph. +# [ejabberd_*] +# env.days 1 7 30 +# +#%# family=auto +#%# capabilities=autoconf suggest + +EJCTL=$(which ejabberdctl) +if [ "$1" == "autoconf" ]; then + if [ -x "$EJCTL" > /dev/null ]; then + echo yes + exit 0 + fi + echo "no (ejabberdctl not found)" + exit 1 +fi + +if [ "$1" == "suggest" ]; then + echo "connections" + echo "users" + echo "registrations" + echo "statuses" + echo "memory" + echo "threads" + echo "usersindays" + echo "uptime" + exit 0 +fi + +# trying to autodetect running vhosts. +if [ -z "$vhosts" ]; then + for CFGPATH in /etc/ejabberd /usr/local/ejabberd/etc; do + if [ -f "$CFGPATH/ejabberd.cfg" ]; then + EJCFG=$CFGPATH/ejabberd.cfg; + fi + done + if [ -z "$EJCFG" ]; then + echo "Unable to find ejabberd.cfg. Exiting." > /dev/stderr + exit -1 + fi + # 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); +fi + +# get ejabberd PID +# in GNU/Linux Debian Lenny release the pidof command can be executed only by root +#EJPID=$(pidof -s /usr/lib/erlang/erts-5.6.3/bin/beam.smp) +EJPID=$(ps -ef | awk '/ejabberd/ && /\/bin\/beam(.smp)?/ {print $2}') + +if [ -z "$vhosts" ]; then + echo "No vhosts to sample." > /dev/stderr + echo "Please set env.vhosts in plugins-conf.d/munin-node." > /dev/stderr + exit -1 +fi + +MODE=`basename $0 | sed 's/^ejabberd_//g'` + +if ! [ "$MODE" == "connections" -o "$MODE" == "users" \ + -o "$MODE" == "registrations" -o "$MODE" == "statuses" \ + -o "$MODE" == "memory" -o "$MODE" == "threads" \ + -o "$MODE" == "usersindays" -o "$MODE" == "uptime" ]; then + echo "ERROR: Unknown mode \"$MODE\". Exiting." > /dev/stderr + exit -1 +fi + +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_info This graph shows a statistic of ejabberd' + + if [ "$MODE" == "connections" ]; then + echo 'graph_title Server-to-server conections' + echo 'graph_vlabel s2s' + echo 's2s_connections_out.label incoming s2s connections' + echo 's2s_connections_out.info Number of outgoing server to server connections' + echo 's2s_connections_in.label outgoing s2s connections' + echo 's2s_connections_in.info Number of incoming server to server connections' + elif [ "$MODE" == "users" ]; then + echo 'graph_title Connected users' + echo 'graph_vlabel users' + for host in $vhosts; do + formathost=$(echo $host | tr '.' '_') + echo "connected_users_$formathost.label $host connected users"; + echo "connected_unique_users_$formathost.label $host unique connected users"; + done; + elif [ "$MODE" == "registrations" ]; then + echo 'graph_title Number of registered users' + echo 'graph_vlabel users' + for host in $vhosts; do + formathost=$(echo $host | tr '.' '_') + echo "registered_$formathost.label $host registered users"; + echo "registered_$formathost.info Registered users for vhost $host" + done; + elif [ "$MODE" == "statuses" ]; then + echo 'graph_title Users with statuses' + echo 'graph_vlabel users' + for host in $vhosts; do + for status in $statuses; do + formathost=$(echo $host | tr '.' '_') + echo "status_${formathost}_${status}.label $status on $host"; + echo "status_${formathost}_${status}.info Number of users with status $status on $host [available, away, xa=not available, dnd=(do not disturb) or (busy), chat=free for chat]"; + done; + done; + elif [ "$MODE" == "threads" ]; then + echo 'graph_title Threads of ejabberd process' + echo 'graph_vlabel threads' + echo "ejabberd_threads.label number of threads"; + echo "ejabberd_threads.info Number of threads of ejabberd process"; + elif [ "$MODE" == "usersindays" ]; then + echo 'graph_title Active users in last days' + echo 'graph_vlabel users' + for host in $vhosts; do + for num in $days; do + formathost=$(echo $host | tr '.' '_') + echo "usersindays_${formathost}_${num}.label active users on $host in last $num days"; + echo "usersindays_${formathost}_${num}.info Number of users active on $host in last $num days"; + done; + done; + elif [ "$MODE" == "uptime" ]; then + echo 'graph_title Uptime of ejabberd server' + echo 'uptime in days' + echo "uptime.label uptime" + echo 'uptime.draw AREA' + 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 +fi + +if [ "$MODE" == "users" ]; then + for host in $vhosts; do + formathost=$(echo $host | tr '.' '_') + 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}')"; + done + exit 0 +fi + +if [ "$MODE" == "registrations" ]; then + for host in $vhosts; do + formathost=$(echo $host | tr '.' '_') + num=$($EJCTL vhost $host stats registeredusers) + if [ "$?" != 0 ]; then + num="U" + fi + echo "registered_$formathost.value $num"; + done + exit 0 +fi + +if [ "$MODE" == "statuses" ]; then + for host in $vhosts; do + formathost=$(echo $host | tr '.' '_') + for status in $statuses; do + num=$($EJCTL vhost $host status-num $status) + if [ "$?" != 0 ]; then + num="U" + fi + echo "status_${formathost}_${status}.value $num"; + done + done + exit 0 +fi + +if [ "$MODE" == "memory" ]; then + 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)" + exit 0 +fi + +if [ "$MODE" == "threads" ]; then + echo "ejabberd_threads.value $(awk '/Threads/ {print $2}' /proc/${EJPID}/status)" + exit 0 +fi + +if [ "$MODE" == "usersindays" ]; then + for host in $vhosts; do + for num in $days; do + formathost=$(echo $host | tr '.' '_') + 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