Projet

Général

Profil

Révision 0ae7b31a

ID0ae7b31a7b6c8df66293310fbbc0755a233475a7
Parent 0397aff3
Enfant 6f6a48ff

Ajouté par Peter Viskup il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/ejabberd_
1
#!/bin/bash
2
# 
3
# Munin plugin for ejabberd2.
4
#
5
# Written by Lasse Karstensen <lkarsten@hyse.org> 2007-05-27.
6
# Based on ejabberd-plugin by Christian Dröge <Christian@draugr.de>
7
#
8
# Status, memory, threads, uptime, usersindays, ejabberd2 and other code
9
# optimisation by Peter Viskup <skupko.sk@gmail.com>
10
#
11
# As connected users, registered users and server-connections have somewhat
12
# different scales, this plugin uses munins suggest feature to create three
13
# different graphs.
14
# 
15
# ejabberd_connections
16
# ejabberd_users
17
# ejabberd_registrations
18
# ejabberd_statuses
19
# ejabberd_memory
20
# ejabberd_threads
21
# ejabberd_usersindays
22
# ejabberd_uptime
23
#
24
# use command
25
# ln -s ejabberd_ ejabberd_(connections|memory|registrations|statuses|threads|uptime|users|usersindays) 
26
# to activate.
27
#
28
# If the autodetect-feature for vhosts breaks, you can set  
29
# """
30
# [ejabberd_*]
31
# env.vhosts foo.com bar.com
32
# """
33
# in plugin-conf.d/munin-node to override it.
34
# (user root may also be smart/not so smart depending on your setup.)
35
# 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.
36
# http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html
37
#
38
# For monitoring user statuses - define statuses environment variable:
39
# (you can monitor only some of them)
40
# [ejabberd_*]
41
# env.statuses available away chat xa
42
#
43
# For usersindays statistics define days environment variable
44
# Be careful on high loaded servers, because it will plot all days in one
45
# graph.
46
# [ejabberd_*]
47
# env.days 1 7 30
48
#
49
#%# family=auto
50
#%# capabilities=autoconf suggest
51

  
52
EJCTL=$(which ejabberdctl)
53
if [ "$1" == "autoconf" ]; then
54
        if [ -x "$EJCTL" > /dev/null ]; then
55
                echo yes
56
                exit 0
57
        fi
58
        echo "no (ejabberdctl not found)"
59
        exit 1
60
fi
61

  
62
if [ "$1" == "suggest" ]; then
63
    echo "connections"
64
    echo "users"
65
    echo "registrations"
66
    echo "statuses"
67
    echo "memory"
68
    echo "threads"
69
    echo "usersindays"
70
    echo "uptime"
71
    exit 0
72
fi
73

  
74
# trying to autodetect running vhosts.
75
if [ -z "$vhosts" ]; then
76
    for CFGPATH in /etc/ejabberd /usr/local/ejabberd/etc; do
77
	if [ -f "$CFGPATH/ejabberd.cfg" ]; then
78
	    EJCFG=$CFGPATH/ejabberd.cfg;
79
	fi
80
    done
81
    if [ -z "$EJCFG" ]; then
82
        echo "Unable to find ejabberd.cfg. Exiting." > /dev/stderr
83
        exit -1
84
    fi
85
    # you have to have all of vhosts defined on one line in $EJCFG or in plugins-conf.d/munin-node config file
86
    vhosts=$(awk '/^\s*{hosts/ {gsub( /\{\s?hosts\s?,|[\",\[\]]|\}\s?.|localhost/ ,""); print;}' $EJCFG);
87
fi
88

  
89
# get ejabberd PID
90
# in GNU/Linux Debian Lenny release the pidof command can be executed only by root
91
#EJPID=$(pidof -s /usr/lib/erlang/erts-5.6.3/bin/beam.smp)
92
EJPID=$(ps -ef | awk '/ejabberd/ && /\/bin\/beam(.smp)?/ {print $2}')
93

  
94
if [ -z "$vhosts" ]; then
95
    echo "No vhosts to sample." > /dev/stderr
96
    echo "Please set env.vhosts in plugins-conf.d/munin-node." > /dev/stderr
97
    exit -1
98
fi
99

  
100
MODE=`basename $0 | sed 's/^ejabberd_//g'`
101

  
102
if ! [ "$MODE" == "connections" -o "$MODE" == "users" \
103
  -o "$MODE" == "registrations" -o "$MODE" == "statuses" \
104
  -o "$MODE" == "memory" -o "$MODE" == "threads" \
105
  -o "$MODE" == "usersindays" -o "$MODE" == "uptime" ]; then
106
    echo "ERROR: Unknown mode \"$MODE\". Exiting." > /dev/stderr
107
    exit -1
108
fi
109

  
110
if [ "$1" = "config" ]; then
111
    if [ "$MODE" == "memory" ]; then
112
	echo 'graph_args --base 1024 -l 0'
113
	echo 'graph_scale yes'
114
	echo 'graph_category ejabberd'
115
	echo 'graph_info This graph shows a statistic of ejabberd'
116
	echo 'graph_title Memory of ejabberd process'
117
	echo 'graph_vlabel Bytes'
118
	echo "ejabberd_memory_size.label actual memory";
119
	echo "ejabberd_memory_size.info Memory used by ejabberd process in Bytes";
120
	echo "ejabberd_memory_peak.label memory peak";
121
	echo "ejabberd_memory_peak.info Memory peak of ejabberd process in Bytes";
122
    else
123
    echo 'graph_args --base 1000 -l 0'
124
    echo 'graph_scale no'
125
    echo 'graph_category ejabberd'
126
    echo 'graph_info This graph shows a statistic of ejabberd'
127

  
128
    if [ "$MODE" == "connections" ]; then
129
	echo 'graph_title Server-to-server conections'
130
	echo 'graph_vlabel s2s'
131
        echo 's2s_connections_out.label incoming s2s connections'
132
        echo 's2s_connections_out.info Number of outgoing server to server connections'
133
        echo 's2s_connections_in.label outgoing s2s connections'
134
        echo 's2s_connections_in.info Number of incoming server to server connections'
135
    elif [ "$MODE" == "users" ]; then
136
	echo 'graph_title Connected users'
137
	echo 'graph_vlabel users'
138
	for host in $vhosts; do
139
	    formathost=$(echo $host | tr '.' '_')
140
	    echo "connected_users_$formathost.label $host connected users";
141
	    echo "connected_unique_users_$formathost.label $host unique connected users";
142
	done;
143
    elif [ "$MODE" == "registrations" ]; then
144
	echo 'graph_title Number of registered users'
145
	echo 'graph_vlabel users'
146
	for host in $vhosts; do
147
	    formathost=$(echo $host | tr '.' '_')
148
	    echo "registered_$formathost.label $host registered users";
149
	    echo "registered_$formathost.info Registered users for vhost $host"
150
	done;
151
    elif [ "$MODE" == "statuses" ]; then
152
	echo 'graph_title Users with statuses'
153
	echo 'graph_vlabel users'
154
	for host in $vhosts; do
155
		for status in $statuses; do
156
			formathost=$(echo $host | tr '.' '_')
157
		   echo "status_${formathost}_${status}.label $status on $host"; 
158
	  	 	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]";
159
		done;
160
	done;
161
    elif [ "$MODE" == "threads" ]; then
162
	echo 'graph_title Threads of ejabberd process'
163
	echo 'graph_vlabel threads'
164
	echo "ejabberd_threads.label number of threads";
165
	echo "ejabberd_threads.info Number of threads of ejabberd process";
166
    elif [ "$MODE" == "usersindays" ]; then
167
	echo 'graph_title Active users in last days'
168
	echo 'graph_vlabel users'
169
	for host in $vhosts; do
170
		for num in $days; do
171
			formathost=$(echo $host | tr '.' '_')
172
			echo "usersindays_${formathost}_${num}.label active users on $host in last $num days";
173
			echo "usersindays_${formathost}_${num}.info Number of users active on $host in last $num days";
174
		done;
175
	done;
176
    elif [ "$MODE" == "uptime" ]; then
177
	echo 'graph_title Uptime of ejabberd server'
178
	echo 'uptime in days'
179
	echo "uptime.label uptime"
180
	echo 'uptime.draw AREA'
181
    fi
182
    fi
183
    exit 0
184
fi
185

  
186
if [ "$MODE" == "connections" ]; then
187
    echo "s2s_connections_out.value $($EJCTL outgoing-s2s-number)"
188
    echo "s2s_connections_in.value $($EJCTL incoming-s2s-number)"
189
    exit 0
190
fi
191

  
192
if [ "$MODE" == "users" ]; then
193
    for host in $vhosts; do
194
	formathost=$(echo $host | tr '.' '_')
195
	echo "connected_users_$formathost.value $($EJCTL vhost $host stats onlineusers)"; 
196
	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}')"; 
197
    done
198
    exit 0
199
fi
200

  
201
if [ "$MODE" == "registrations" ]; then
202
    for host in $vhosts; do
203
	formathost=$(echo $host | tr '.' '_')
204
	num=$($EJCTL vhost $host stats registeredusers)
205
        if [ "$?" != 0 ]; then
206
            num="U"
207
        fi
208
	echo "registered_$formathost.value $num"; 
209
    done
210
    exit 0
211
fi
212

  
213
if [ "$MODE" == "statuses" ]; then
214
   for host in $vhosts; do
215
	formathost=$(echo $host | tr '.' '_')
216
		for status in $statuses; do
217
			num=$($EJCTL vhost $host status-num $status)
218
			if [ "$?" != 0 ]; then
219
				num="U"
220
			fi
221
			echo "status_${formathost}_${status}.value $num";
222
		done
223
	 done
224
    exit 0
225
fi
226

  
227
if [ "$MODE" == "memory" ]; then
228
    echo "ejabberd_memory_size.value $(awk '/VmSize/ {print $2*1024}' /proc/${EJPID}/status)"
229
    echo "ejabberd_memory_peak.value $(awk '/VmPeak/ {print $2*1024}' /proc/${EJPID}/status)"
230
    exit 0
231
fi
232

  
233
if [ "$MODE" == "threads" ]; then
234
    echo "ejabberd_threads.value $(awk '/Threads/ {print $2}' /proc/${EJPID}/status)"
235
    exit 0
236
fi
237

  
238
if [ "$MODE" == "usersindays" ]; then
239
        for host in $vhosts; do
240
                for num in $days; do
241
                        formathost=$(echo $host | tr '.' '_')
242
                        echo "usersindays_${formathost}_${num}.value $($EJCTL vhost $host num-active-users $num)";
243
                done;
244
        done;
245
	exit 0
246
fi
247

  
248
if [ "$MODE" == "uptime" ]; then
249
	echo "uptime.value $($EJCTL stats uptime-seconds | awk '{printf "%.2f", $1/86400}')"
250
fi

Formats disponibles : Unified diff