Created
June 16, 2010 13:15
-
-
Save groupdock/440656 to your computer and use it in GitHub Desktop.
ejabberd munin plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Updated/Modified by Luc Castera (2010-06-14). Intellum Inc. | |
# (http://www.intellum.com) | |
# | |
# Munin plugin for ejabberd2. | |
# | |
# Written by Lasse Karstensen <[email protected]> 2007-05-27. | |
# Based on ejabberd-plugin by Christian Dröge <[email protected]> | |
# | |
# Memory, threads, ejabberd2 and other code | |
# optimisation by Peter Viskup <[email protected]> | |
# | |
# 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_memory | |
# ejabberd_threads | |
# ejabberd_mnesia_records | |
# ejabberd_mnesia_memory | |
# | |
# use command | |
# ln -s ejabberd_ ejabberd_(connections|memory|registrations|threads|users|ejabberd_mnesia_memory|ejabberd_mnesia_records) | |
# 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 | |
# | |
#%# family=auto | |
#%# capabilities=autoconf suggest | |
EJCTL=/path/to/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 "memory" | |
echo "threads" | |
echo "mnesia_records" | |
echo "mnesia_memory" | |
exit 0 | |
fi | |
if [ "$1" == "debug" ]; then | |
echo $EJCTL | |
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" == "mnesia_records" \ | |
-o "$MODE" == "mnesia_memory" \ | |
-o "$MODE" == "memory" \ | |
-o "$MODE" == "threads" ]; 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 outgoing s2s connections' | |
echo 's2s_connections_out.info Number of outgoing server to server connections' | |
echo 's2s_connections_in.label incoming 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' | |
echo "connected_users.label connected users"; | |
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_users_$formathost.label $host registered users"; | |
echo "registered_users_$formathost.info Registered users for vhost $host" | |
done; | |
elif [ "$MODE" == "mnesia_records" ]; then | |
echo 'graph_title Mnesia Records' | |
echo 'graph_vlabel Number of records' | |
echo 'mnesia_records_pubsub_subscription.label pubsub subscriptions' | |
echo 'mnesia_records_pubsub_subscription.info Number of mnesia pubsub subscription records' | |
echo 'mnesia_records_offline_msg.label offline messages' | |
echo 'mnesia_records_offline_msg.info Number of offline messages' | |
echo 'mnesia_records_pubsub_item.label pubsub items' | |
echo 'mnesia_records_pubsub_item.info Number of pubsub items' | |
echo 'mnesia_records_pubsub_state.label pubsub states' | |
echo 'mnesia_records_pubsub_state.info Number of pubsub states' | |
echo 'mnesia_records_pubsub_node.label pubsub nodes' | |
echo 'mnesia_records_pubsub_node.info Number of pubsub nodes' | |
echo 'mnesia_records_pubsub_index.label pubsub indexes' | |
echo 'mnesia_records_pubsub_index.info Number of pubsub indexes' | |
elif [ "$MODE" == "mnesia_memory" ]; then | |
echo 'graph_args --base 1024 -l 0' | |
echo 'graph_scale yes' | |
echo 'graph_category ejabberd' | |
echo 'graph_title Mnesia Memory Usage' | |
echo 'graph_vlabel Bytes' | |
echo 'mnesia_memory_pubsub_subscription.label pubsub subcription memory' | |
echo 'mnesia_memory_pubsub_subscription.info Memory used by pubsub subcriptions' | |
echo 'mnesia_memory_offline_msg.label offline messages memory' | |
echo 'mnesia_memory_offline_msg.info Memory used by offline messages' | |
echo 'mnesia_memory_pubsub_item.label pubsub items memory' | |
echo 'mnesia_memory_pubsub_item.info Memory used by pubsub items' | |
echo 'mnesia_memory_pubsub_state.label pubsub states memory' | |
echo 'mnesia_memory_pubsub_state.info Memory used by pubsub states' | |
echo 'mnesia_memory_pubsub_node.label pubsub nodes memory' | |
echo 'mnesia_memory_pubsub_node.info Memory used by pubsub nodes' | |
echo 'mnesia_memory_pubsub_index.label pubsub indexes memory' | |
echo 'mnesia_memory_pubsub_index.info Memory used by pubsub indexes' | |
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"; | |
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 | |
echo "connected_users.value $($EJCTL connected_users_number)"; | |
exit 0 | |
fi | |
if [ "$MODE" == "registrations" ]; then | |
for host in $vhosts; do | |
formathost=$(echo $host | tr '.' '_') | |
num=$($EJCTL registered_users $host | wc -l) | |
if [ "$?" != 0 ]; then | |
num="U" | |
fi | |
echo "registered_users_$formathost.value $num"; | |
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" == "mnesia_records" ]; then | |
echo "mnesia_records_pubsub_subscription.value $($EJCTL mnesia info | grep pubsub_subscription | grep with | awk '{print $3}')" | |
echo "mnesia_records_offline_msg.value $($EJCTL mnesia info | grep offline_msg | grep with | awk '{print $4}')" | |
echo "mnesia_records_pubsub_item.value $($EJCTL mnesia info | grep pubsub_item | grep with | awk '{print $4}')" | |
echo "mnesia_records_pubsub_state.value $($EJCTL mnesia info | grep pubsub_state | grep with | awk '{print $4}')" | |
echo "mnesia_records_pubsub_node.value $($EJCTL mnesia info | grep pubsub_node | grep with | awk '{print $4}')" | |
echo "mnesia_records_pubsub_index.value $($EJCTL mnesia info | grep pubsub_index | grep with | awk '{print $4}')" | |
exit 0 | |
fi | |
if [ "$MODE" == "mnesia_memory" ]; then | |
echo "mnesia_memory_pubsub_subscription.value $($EJCTL mnesia info | grep pubsub_subscription | grep with | awk '{print $6}')" | |
echo "mnesia_memory_offline_msg.value $($EJCTL mnesia info | grep offline_msg | grep with | awk '{print $7}')" | |
echo "mnesia_memory_pubsub_item.value $($EJCTL mnesia info | grep pubsub_item | grep with | awk '{print $7}')" | |
echo "mnesia_memory_pubsub_state.value $($EJCTL mnesia info | grep pubsub_state | grep with | awk '{print $7}')" | |
echo "mnesia_memory_pubsub_node.value $($EJCTL mnesia info | grep pubsub_node | grep with | awk '{print $7}')" | |
echo "mnesia_memory_pubsub_index.value $($EJCTL mnesia info | grep pubsub_index | grep with | awk '{print $7}')" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment