blob: 1b53683de165a8f2451b49cd8012f8b48aab4689 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
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 ejabberd'
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'
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
connected_users=`$EJCTL connected-users`
for host in $vhosts; do
formathost=$(echo $host | tr '.-' '_')
echo -n "connected_users_$formathost.value ";
echo $connected_users | grep "@$host" | wc -l
echo -n "connected_unique_users_$formathost.value ";
echo $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 ";
stat_file="/var/lib/munin/plugin-state/ejabberd_registrations_${host}"
if [ -f $stat_file ]; then
num=$(cat $stat_file)
else
num=$($EJCTL registered-users $host)
fi
if [ "$?" != 0 ]; then
echo "U"
else
echo $num | wc -w
fi
done
exit 0
fi
|