/usr/share/munin/plugins/ejabberd_ is in munin-plugins-extra 2.0.37-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | #!/bin/sh
# -*- sh -*-
: << =cut
=head1 NAME
ejabberd_ - Munin wildcard plugin to monitor ejabberd2
=head1 CONFIGURATION
As connected users, registered users and server-connections have
somewhat different scales, this plugin uses munins suggest feature to
create the following graphs:
ejabberd_connections
ejabberd_memory
ejabberd_registrations
ejabberd_statuses
ejabberd_threads
ejabberd_uptime
ejabberd_users
ejabberd_usersindays
If the autodetect-feature for vhosts breaks, you can set
=over 4
[ejabberd_*]
env.vhosts foo.com bar.com
=back
in a file in plugin-conf.d to override it. ("user root" may also be
smart/not so smart depending on your setup).
For monitoring user statuses - define statuses environment variable:
(you can monitor only some of them)
=over 4
[ejabberd_*]
env.statuses available away chat xa
=back
For usersindays statistics define days environment variable. Be
careful on high loaded servers, because it will plot all days in one
graph.
=over 4
[ejabberd_*]
env.days 1 7 30
=back
If your ejabberd.cfg cannot be found you can se it this way
=over 4
[ejabberd_*]
env.configfile /etc/ejabberd/ejabberd.cfg
=back
=head1 MAGIC MARKERS
#%# family=contrib
#%# capabilities=autoconf suggest
=head1 AUTHOR
Written by Lasse Karstensen <lkarsten@hyse.org>. Based on
ejabberd-plugin by Christian Dröge <Christian@draugr.de>
Status, memory, threads, uptime, usersindays, ejabberd2 and other code
optimisation by Peter Viskup <skupko.sk@gmail.com>
=head1 LICENSE
Unknown
=head1 BUGS
Previously the documentation for this plugin mentioned RRDs limit on
data series names. Munin works around this limit and the restriction
does not apply.
There is no way to configure the path to ejabberdctl.
=cut
set -eu
# configurable environment variables
# list of days (space-separated) for the graph "usersindays"
days=${days:-"1 7 30"}
# list of client statuses (space-separated) for the graph "statuses"
statuses=${statuses:-"available away chat xa"}
# statically configured list of vhosts provided by the ejabberd server
vhosts=${vhosts:-}
# location of ejabberd configuration file for parsing the configured vhosts
# (empty: search in default locations)
configfile=${configfile:-}
EJCTL=$(which ejabberdctl 2>/dev/null)
# 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}')
SUPPORTED_MODES="connections users registrations statuses memory threads usersindays uptime"
# shellcheck disable=SC1090
. "$MUNIN_LIBDIR/plugins/plugin.sh"
if [ "${1:-}" = "autoconf" ]; then
if [ -n "$EJCTL" ] && [ -x "$EJCTL" ]; then
echo yes
else
echo "no (ejabberdctl not found in path)"
fi
exit 0
fi
if [ "${1:-}" = "suggest" ]; then
for mode in $SUPPORTED_MODES; do
echo "$mode"
done
exit 0
fi
# Try to parse a yaml based configuration file for ejabberd. We just hope for a non-cluttered
# format - otherwise our stupid parser will fail. See below for acceptable format examples.
parse_vhosts_from_config_yaml() {
local filename="$1"
local vhosts
# try to parse a single-line yaml list, e.g.:
# hosts: ["foo.example.org", 'bar.example.com']
vhosts=$(grep -E "^hosts:\s*\[" "$filename" \
| sed -E 's/^.*\[(.+)].*$/\1/' \
| tr "," "\n" \
| sed -E 's/^.*["'\''](.+)["'\''].*$/\1/')
if [ -z "$vhosts" ]; then
# try to parse a multi-line yaml list, e.g.:
# hosts:
# - "foo.example.org"
# - 'bar.example.com'
vhosts=$(grep -vE '^(\s*#|$)' "$filename" \
| sed -n '/^hosts:$/,/^\w/p;' \
| grep "^\s*-" \
| sed -E 's/^.+["'\''](.*)["'\'']\s*$/\1/')
fi
echo "$vhosts"
}
# Try to parse the old ejabberd configuration format (*.cfg).
# Output one vhost per line.
parse_vhosts_from_config_cfg() {
local filename="$1"
awk '/^\s*{hosts/ {gsub( /\{\s?hosts\s?,|[\",\[\]]|\}\s?.|localhost/ ,""); print;}' "$filename"
}
# Search for the configuration file and parse its vhosts definition.
# Either a yaml file or a cfg file will be parsed automatically.
# The function will either fail (returning an errorcode) or output the vhosts (one per line).
parse_vhosts_from_config() {
local cfg_dir
local cfg_file
local vhosts
if [ -n "$configfile" ]; then
# a specific filename was configured
if [ ! -f "$configfile" ]; then
echo "The filename defined in the 'configfile' setting does not exist: $configfile" >&2
return 1
fi
else
# search in default locations
for cfg_dir in /etc/ejabberd /etc/ejabber /usr/local/ejabberd/etc; do
for cfg_file in ejabberd.cfg ejabberd.yml; do
if [ -f "$cfg_dir/$cfg_file" ]; then
configfile=$cfg_dir/$cfg_file
break
fi
done
if [ -n "$configfile" ]; then
break
fi
done
fi
if [ -z "$configfile" ]; then
echo "Unable to find ejabberd config file. Maybe specify 'configfile' setting." >&2
return 1
else
# we found a config (or its location was specified)
if echo "$configfile" | grep -qi "\.cfg$"; then
vhosts=$(parse_vhosts_from_config_cfg "$configfile")
else
vhosts=$(parse_vhosts_from_config_yaml "$configfile")
fi
if [ -z "$vhosts" ]; then
echo "Failed to parse vhosts from configuration file: $configfile" >&2
echo "Maybe you want to either simplify the format of the configuration (for our" \
"stupid parser) or specify the 'vhosts' environment variable directly." >&2
return 1
else
echo "$vhosts"
fi
fi
}
# the vhosts can be defined via environment or parsed
if [ -z "$vhosts" ]; then
# exit in case of failure (error messages were emitted before)
vhosts=$(parse_vhosts_from_config) || exit 1
fi
MODE=$(basename "$0" | sed 's/^ejabberd_//g')
if ! echo "$SUPPORTED_MODES" | grep -qwF "$MODE"; then
echo "ERROR: Unknown mode '$MODE'. Exiting." >&2
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 connections'
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=$(clean_fieldname "$host")
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=$(clean_fieldname "$host")
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=$(clean_fieldname "$host")
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=$(clean_fieldname "$host")
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 'graph_vlabel 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=$(clean_fieldname "$host")
echo "connected_users_$formathost.value $("$EJCTL" stats-host onlineusers "$host")"
echo "connected_unique_users_$formathost.value $("$EJCTL" connected-users | awk -v "var=$host" -v count=0 -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=$(clean_fieldname "$host")
num=$("$EJCTL" stats-host registeredusers "$host") || num="U"
echo "registered_$formathost.value $num"
done
exit 0
fi
if [ "$MODE" = "statuses" ]; then
for host in $vhosts; do
formathost=$(clean_fieldname "$host")
for status in $statuses; do
num=$("$EJCTL" status-num-host "$host" "$status") || num="U"
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=$(clean_fieldname "$host")
echo "usersindays_${formathost}_${num}.value $("$EJCTL" num-active-users "$host" "$num")"
done
done
exit 0
fi
if [ "$MODE" = "uptime" ]; then
echo "uptime.value $("$EJCTL" stats uptimeseconds | awk '{printf "%.2f", $1/86400}')"
fi
|