mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Add ejabberd_resources_ plugin and it's image
This commit is contained in:
parent
0cef46c0cf
commit
783f5df9b4
2 changed files with 231 additions and 0 deletions
231
plugins/ejabberd/ejabberd_resources_/ejabberd_resources_
Executable file
231
plugins/ejabberd/ejabberd_resources_/ejabberd_resources_
Executable file
|
@ -0,0 +1,231 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ejabberd_resources_ revision 3 (Nov 2013)
|
||||
#
|
||||
# Tested with ejabberd 2.1.x
|
||||
#
|
||||
# This plugin is capable to show:
|
||||
# - ejabberd memory usage (RSS, VSZ, erlang internal)
|
||||
# - ejabberd ports/processes usage
|
||||
# - online/registered users by vhost
|
||||
#
|
||||
# Required permissions:
|
||||
# - read ejabberdctl configuration file
|
||||
# - connect to a running ejabberd node
|
||||
#
|
||||
# OS: *NIX
|
||||
#
|
||||
# Author: Artem Sheremet <dot.doom@gmail.com>
|
||||
#
|
||||
# Configuration:
|
||||
# - set env.ejabberdctl_cfg to ejabberdctl.cfg path if necessary
|
||||
# - or set env.ERLANG_NODE, env.EJABBERD_PID_PATH to proper values manually
|
||||
# - set erl_path to unregular erlang interpreter cli location
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf suggest
|
||||
|
||||
EJABBERDCTL_CFG=${ejabberdctl_cfg:-/etc/ejabberd/ejabberdctl.cfg}
|
||||
source $EJABBERDCTL_CFG 2>/dev/null
|
||||
source $MUNIN_LIBDIR/plugins/plugin.sh
|
||||
|
||||
ERLANG_HOST=${ERLANG_NODE/*@/}
|
||||
ERLANG_MUNIN_NODE=munin
|
||||
|
||||
ERL=${erl_path:-$(which erl)}
|
||||
|
||||
function ejabberd_exec() {
|
||||
COMMAND=${1//\"/\\\"}
|
||||
su - ejabberd $ERL -noinput \
|
||||
-sname $ERLANG_MUNIN_NODE@$ERLANG_HOST \
|
||||
-noinput \
|
||||
-hidden \
|
||||
-eval "try {ok,S,_} = erl_scan:string(\"$COMMAND\"),
|
||||
{ok,P} = erl_parse:parse_exprs(S),
|
||||
{value,V,_} = rpc:call('$ERLANG_NODE', erl_eval, exprs, [P,[]]),
|
||||
io:format(\"~p\n\", [V])
|
||||
catch
|
||||
_:Err -> io:format(\"~p\n\", [Err])
|
||||
end." \
|
||||
-s init stop
|
||||
}
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
RESOURCE_TYPE="${SCRIPT_NAME/ejabberd_resources_/}"
|
||||
RESOURCE_BASE=1000
|
||||
[ "$RESOURCE_TYPE" = "memory" ] && RESOURCE_BASE=1024
|
||||
|
||||
function hosts_list() {
|
||||
ejabberd_exec 'ejabberd_config:get_global_option(hosts).' | tr '[]",' ' '
|
||||
}
|
||||
|
||||
function ejabberd_report_online_users() {
|
||||
[ "$1" = "config" ] && echo 'graph_vlabel users'
|
||||
for host in $(hosts_list); do
|
||||
local clean_host=$(clean_fieldname $host)
|
||||
local ejabberd_command="length(ejabberd_sm:get_vh_session_list(\"$host\"))"
|
||||
if [ "$1" = "config" ]; then
|
||||
cat <<CONFIG
|
||||
${clean_host}.draw AREASTACK
|
||||
${clean_host}.label $host
|
||||
${clean_host}.info $ejabberd_command
|
||||
CONFIG
|
||||
else
|
||||
echo "$clean_host.value $(ejabberd_exec ${ejabberd_command}.)"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function ejabberd_report_registered_users() {
|
||||
[ "$1" = "config" ] && echo 'graph_vlabel users'
|
||||
for host in $(hosts_list); do
|
||||
local clean_host=$(clean_fieldname $host)
|
||||
local ejabberd_command="ejabberd_auth:get_vh_registered_users_number(\"$host\")"
|
||||
if [ "$1" = "config" ]; then
|
||||
cat <<CONFIG
|
||||
${clean_host}.draw AREASTACK
|
||||
${clean_host}.label $host
|
||||
${clean_host}.info $ejabberd_command
|
||||
CONFIG
|
||||
else
|
||||
echo "$clean_host.value $(ejabberd_exec ${ejabberd_command}.)"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function ejabberd_report_memory() {
|
||||
if [ "$1" = "config" ]; then
|
||||
cat <<CONFIG
|
||||
graph_vlabel bytes
|
||||
rss.draw LINE2
|
||||
rss.label rss
|
||||
rss.info Resident set size
|
||||
vsz.draw LINE2
|
||||
vsz.label vsz
|
||||
vsz.info Virtual memory size
|
||||
CONFIG
|
||||
for memory_type in total processes system atom binary code ets; do
|
||||
cat <<CONFIG
|
||||
$memory_type.draw LINE2
|
||||
$memory_type.label $memory_type
|
||||
CONFIG
|
||||
done
|
||||
cat <<INFO_FROM_DOC
|
||||
total.info The total amount of memory currently allocated, which is the same as the sum of memory size for processes and system.
|
||||
processes.info The total amount of memory currently allocated by the Erlang processes.
|
||||
system.info The total amount of memory currently allocated by the emulator that is not directly related to any Erlang process. Memory presented as processes is not included in this memory.
|
||||
atom.info The total amount of memory currently allocated for atoms. This memory is part of the memory presented as system memory.
|
||||
binary.info The total amount of memory currently allocated for binaries. This memory is part of the memory presented as system memory.
|
||||
code.info The total amount of memory currently allocated for Erlang code. This memory is part of the memory presented as system memory.
|
||||
ets.info The total amount of memory currently allocated for ets tables. This memory is part of the memory presented as system memory.
|
||||
INFO_FROM_DOC
|
||||
else
|
||||
pid=$(<$EJABBERD_PID_PATH)
|
||||
for memory_type in rss vsz; do
|
||||
memory_value=$(ps -p $pid -o $memory_type=)
|
||||
let memory_value=$memory_value*1024
|
||||
echo "$memory_type.value $memory_value"
|
||||
done
|
||||
ejabberd_exec 'erlang:memory().' | tr '"[]{}' ' ' | grep -Fv _used |
|
||||
while read memory_entry; do
|
||||
clean_entry=${memory_entry/ ,/}
|
||||
entry_name=${clean_entry/,*/}
|
||||
entry_value=${clean_entry/*,/}
|
||||
echo $entry_name.value $entry_value
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function ejabberd_report_ports() {
|
||||
local limit=$(ejabberd_exec 'os:getenv("ERL_MAX_PORTS").' | tr '"' ' ')
|
||||
# string "false" indicates that this variable is not defined, thus a default of 1024
|
||||
[ $limit = false ] && limit=1024
|
||||
local os_limit=$(ejabberd_exec 'os:cmd("ulimit -n").' | tr '"\\n' ' ')
|
||||
if [ $limit -gt $os_limit ]; then
|
||||
local real_limit=$os_limit
|
||||
else
|
||||
local real_limit=$limit
|
||||
fi
|
||||
if [ "$1" = "config" ]; then
|
||||
cat <<CONFIG
|
||||
graph_vlabel ports
|
||||
opened.draw LINE
|
||||
opened.label opened
|
||||
opened.info length(erlang:ports())
|
||||
limit.draw LINE2
|
||||
limit.label limit
|
||||
limit.info ERL_MAX_PORTS environment variable inside ejabberd
|
||||
os_limit.draw LINE2
|
||||
os_limit.label os limit
|
||||
os_limit.info "ulimit -n" from inside of ejabberd
|
||||
CONFIG
|
||||
warning='80%' critical='90%' print_adjusted_thresholds opened $real_limit
|
||||
[ -n "$ERL_MAX_PORTS" ] && cat <<CONFIG_CONFIGURED
|
||||
configured.draw LINE
|
||||
configured.label configured
|
||||
configured.info Configuration file value ERL_MAX_PORTS
|
||||
CONFIG_CONFIGURED
|
||||
else
|
||||
local opened=$(ejabberd_exec 'length(erlang:ports()).')
|
||||
cat <<DATA
|
||||
opened.value $opened
|
||||
limit.value $limit
|
||||
os_limit.value $os_limit
|
||||
DATA
|
||||
[ -n "$ERL_MAX_PORTS" ] && echo "configured.value $ERL_MAX_PORTS"
|
||||
fi
|
||||
}
|
||||
|
||||
function ejabberd_report_processes() {
|
||||
local limit=$(ejabberd_exec 'erlang:system_info(process_limit).')
|
||||
if [ "$1" = "config" ]; then
|
||||
cat <<CONFIG
|
||||
graph_vlabel processes
|
||||
active.draw LINE
|
||||
active.label active
|
||||
active.info erlang:system_info(process_count)
|
||||
limit.draw LINE2
|
||||
limit.label limit
|
||||
limit.info erlang:system_info(process_limit)
|
||||
CONFIG
|
||||
warning='80%' critical='90%' print_adjusted_thresholds active $limit
|
||||
[ -n "$ERL_PROCESSES" ] && cat <<CONFIG_CONFIGURED
|
||||
configured.draw LINE
|
||||
configured.label configured
|
||||
configured.info Configuration file value ERL_PROCESSES
|
||||
CONFIG_CONFIGURED
|
||||
else
|
||||
local active=$(ejabberd_exec 'erlang:system_info(process_count).')
|
||||
cat <<DATA
|
||||
active.value $active
|
||||
limit.value $limit
|
||||
DATA
|
||||
[ -n "$ERL_PROCESSES" ] && echo "configured.value $ERL_PROCESSES"
|
||||
fi
|
||||
}
|
||||
|
||||
case $1 in
|
||||
autoconf)
|
||||
[ -r "$EJABBERDCTL_CFG" ] && echo yes || echo no
|
||||
exit 0
|
||||
;;
|
||||
suggest)
|
||||
cat <<SUGGESTIONS
|
||||
memory
|
||||
processes
|
||||
ports
|
||||
online_users
|
||||
registered_users
|
||||
SUGGESTIONS
|
||||
exit 0
|
||||
;;
|
||||
config)
|
||||
cat <<CONFIG
|
||||
graph_title ejabberd resources - ${RESOURCE_TYPE//_/ }
|
||||
graph_args --base $RESOURCE_BASE --lower-limit 0
|
||||
graph_category ejabberd
|
||||
CONFIG
|
||||
;;
|
||||
esac
|
||||
|
||||
ejabberd_report_${RESOURCE_TYPE} $1
|
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
Loading…
Add table
Add a link
Reference in a new issue