summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormh <mh@immerda.ch>2009-01-26 22:32:58 +0000
committermh <mh@immerda.ch>2009-01-26 22:32:58 +0000
commit2db91aa7f6661d3d5c5d421e5bb9a643b8015ca7 (patch)
treee1fe0fb0c59eae0cff556fccd1f71fb2e0dad9cf
parent02ae451bb17439ff4a8a3f01f9224d1367258906 (diff)
downloadpuppet-ejabberd-2db91aa7f6661d3d5c5d421e5bb9a643b8015ca7.tar.gz
puppet-ejabberd-2db91aa7f6661d3d5c5d421e5bb9a643b8015ca7.tar.bz2
added munin plugin for ejabberd
-rwxr-xr-xfiles/munin/ejabberd_166
-rw-r--r--manifests/init.pp3
-rw-r--r--manifests/munin.pp17
3 files changed, 186 insertions, 0 deletions
diff --git a/files/munin/ejabberd_ b/files/munin/ejabberd_
new file mode 100755
index 0000000..e3a719f
--- /dev/null
+++ b/files/munin/ejabberd_
@@ -0,0 +1,166 @@
+#!/bin/bash
+#
+# Munin plugin for ejabberd.
+#
+# Written by Lasse Karstensen <lkarsten@hyse.org> 2007-05-27.
+# Based on ejabberd-plugin by Christian Dröge <Christian@draugr.de>
+#
+# 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
+#
+# use ln -s ejabberd ejabberd_(connections|users|registrations)
+# 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.)
+#
+#%# family=auto
+#%# capabilities=autoconf suggest
+
+EJCTL=$ejctl
+if [ "$EJCTL" == "" ]; then
+ EJCTL=`which ejabberdctl||echo "/usr/sbin/ejabberdctl"`
+fi
+if [ "$1" == "autoconf" ]; then
+ if [ -x $EJCTL > /dev/null ]; then
+ echo yes
+ exit 0
+ fi
+ echo "no (ejabberdctl not found)"
+ exit 1
+fi
+echo $EJCTL
+
+if [ "$1" == "suggest" ]; then
+ echo "connections"
+ echo "users"
+ echo "registrations"
+ 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
+
+ # this is pretty trivial, and may break if you have many vhosts.
+ vhosts=$(egrep -A5 '^\{hosts' $EJCFG | \
+ egrep -v "^#" | \
+ # make it one whole line.
+ tr '\n' ' ' | \
+ # eat what is before [ and after ] on the line.
+ sed -e 's/.*\[//' -e 's/\].*//' | \
+ # remove the "s
+ sed -e 's/\"//g' | \
+ # clean up whitespaces
+ sed -e 's/ //g' | \
+ sed -e 's/,/ /g' | \
+ # hmm, wonder if this should be here.
+ sed -e 's/localhost//' )
+ # all set!
+ # okay, not so trivial. hope it works. if you get funky results,
+ # try adjusting the "egrep -Ax" above.
+fi
+
+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" ]; then
+ echo "ERROR: Unknown mode \"$MODE\". Exiting." > /dev/stderr
+ exit -1
+fi
+
+if [ "$1" = "config" ]; then
+ echo 'graph_args --base 1000 -l 0'
+ echo 'graph_scale no'
+ echo 'graph_category network'
+ echo 'graph_info This graph shows a statistic of ejabberd '
+
+ if [ "$MODE" == "connections" ]; then
+ 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 ejabberd connected users'
+ echo 'graph_vlabel users'
+# echo 'connected_users.info Number of logged in users'
+# echo 'connected_users.label connected 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 ejabberd registrations'
+ 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;
+ fi
+ exit 0
+fi
+
+
+if [ "$MODE" == "connections" ]; then
+ echo -n "s2s_connections_out.value "
+ $EJCTL outgoing-s2s-number
+ echo -n "s2s_connections_in.value "
+ $EJCTL incoming-s2s-number
+ exit 0
+fi
+
+if [ "$MODE" == "users" ]; then
+# echo -n "connected_unique_users.value "
+# $EJCTL connected-users | awk -F/ '{print $1}' | sort | uniq | wc -l
+
+ for host in $vhosts; do
+ formathost=$(echo $host | tr '.' '_')
+ echo -n "connected_users_$formathost.value ";
+ $EJCTL connected-users | grep "@$host" | wc -l
+ echo -n "connected_unique_users_$formathost.value ";
+ $EJCTL connected-users | grep "@$host" | awk -F/ '{print $1}' | sort | uniq | wc -l
+ done
+ exit 0
+fi
+
+if [ "$MODE" == "registrations" ]; then
+ for host in $vhosts; do
+ formathost=$(echo $host | tr '.' '_')
+ echo -n "registered_$formathost.value ";
+ num=$($EJCTL vhost $host registered-users)
+ if [ "$?" != 0 ]; then
+ echo "U"
+ else
+ echo $num | wc -w
+ fi
+ done
+ exit 0
+fi
+
diff --git a/manifests/init.pp b/manifests/init.pp
index 36cb7ba..cc168b4 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -29,4 +29,7 @@ class ejabberd::base {
require => Package[ejabberd],
}
+ if $use_munin {
+ include ejabberd::munin
+ }
}
diff --git a/manifests/munin.pp b/manifests/munin.pp
new file mode 100644
index 0000000..1ad3e08
--- /dev/null
+++ b/manifests/munin.pp
@@ -0,0 +1,17 @@
+class ejabberd::munin {
+ case $ejabberd_domains {
+ '': { $ejabberd_domains = $fqdn }
+ }
+ munin::plugin::deploy{'ejabberd_users':
+ source => "puppet://$server/ejabberd/munin/ejabberd_",
+ config => "env.vhosts ${$ejabberd_domains}\nuser root"
+ }
+ munin::plugin{'ejabberd_connections':
+ require => Munin::Plugin::Deploy['ejabberd_users'],
+ config => "env.vhosts ${$ejabberd_domains}\nuser root"
+ }
+ munin::plugin{'ejabberd_registrations':
+ require => Munin::Plugin::Deploy['ejabberd_users'],
+ config => "env.vhosts ${$ejabberd_domains}\nuser root"
+ }
+}