1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Add open_files capability to ejabberd_resources_

It appears that erlang port is not bound to an OS file very often.
Thus "ulimit -n" is moved to a separate graph and lsof/fstat is used as
a backend to count the number of files open.
This commit is contained in:
Artem Sheremet 2013-11-15 23:46:37 +03:00
parent 0a0b477768
commit bf9c3caae9

View file

@ -14,6 +14,7 @@
# - connect to a running ejabberd node # - connect to a running ejabberd node
# #
# OS: *NIX # OS: *NIX
# Requires lsof/fstat for open_files.
# #
# Author: Artem Sheremet <dot.doom@gmail.com> # Author: Artem Sheremet <dot.doom@gmail.com>
# #
@ -120,7 +121,7 @@ code.info The total amount of memory currently allocated for Erlang code. This m
ets.info The total amount of memory currently allocated for ets tables. 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 INFO_FROM_DOC
else else
pid=$(<$EJABBERD_PID_PATH) local pid=$(<$EJABBERD_PID_PATH)
for memory_type in rss vsz; do for memory_type in rss vsz; do
memory_value=$(ps -p $pid -o $memory_type=) memory_value=$(ps -p $pid -o $memory_type=)
let memory_value=$memory_value*1024 let memory_value=$memory_value*1024
@ -140,42 +141,69 @@ function ejabberd_report_ports() {
local limit=$(ejabberd_exec 'os:getenv("ERL_MAX_PORTS").' | tr '"' ' ') local limit=$(ejabberd_exec 'os:getenv("ERL_MAX_PORTS").' | tr '"' ' ')
# string "false" indicates that this variable is not defined, thus a default of 1024 # string "false" indicates that this variable is not defined, thus a default of 1024
[ $limit = false ] && limit=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 if [ "$1" = "config" ]; then
cat <<CONFIG cat <<CONFIG
graph_vlabel ports graph_vlabel ports
opened.draw LINE open.draw LINE
opened.label opened open.label open
opened.info length(erlang:ports()) open.info length(erlang:ports())
limit.draw LINE2 limit.draw LINE2
limit.label limit limit.label limit
limit.info ERL_MAX_PORTS environment variable inside ejabberd 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 CONFIG
warning='80%' critical='90%' print_adjusted_thresholds opened $real_limit warning='80%' critical='90%' print_adjusted_thresholds open $limit
[ -n "$ERL_MAX_PORTS" ] && cat <<CONFIG_CONFIGURED [ -n "$ERL_MAX_PORTS" ] && cat <<CONFIG_CONFIGURED
configured.draw LINE configured.draw LINE
configured.label configured configured.label configured
configured.info Configuration file value ERL_MAX_PORTS configured.info Configuration file value ERL_MAX_PORTS
CONFIG_CONFIGURED CONFIG_CONFIGURED
else else
local opened=$(ejabberd_exec 'length(erlang:ports()).') local open=$(ejabberd_exec 'length(erlang:ports()).')
cat <<DATA cat <<DATA
opened.value $opened open.value $open
limit.value $limit limit.value $limit
os_limit.value $os_limit
DATA DATA
[ -n "$ERL_MAX_PORTS" ] && echo "configured.value $ERL_MAX_PORTS" [ -n "$ERL_MAX_PORTS" ] && echo "configured.value $ERL_MAX_PORTS"
fi fi
} }
function open_files_counter_util() {
if hash lsof &>/dev/null; then
echo lsof
return 0
elif hash fstat &>/dev/null; then
echo fstat
return 0
fi
return 1
}
function open_files_number() {
echo $[$($(open_files_counter_util) -np $(<$EJABBERD_PID_PATH) | wc -l)-1]
}
function ejabberd_report_open_files() {
# this spawns a child process, but in most cases the open files limit is inherited
local limit=$(ejabberd_exec 'os:cmd("ulimit -n").' | tr '"\\n' ' ')
if [ "$1" = "config" ]; then
cat <<CONFIG
graph_vlabel open files
open.draw LINE
open.label open
open.info number of open files as reported by $(open_files_counter_util)
limit.draw LINE2
limit.label limit
limit.info "ulimit -n" from inside of ejabberd
CONFIG
warning='80%' critical='90%' print_adjusted_thresholds open $limit
else
cat <<DATA
open.value $(open_files_number)
limit.value $limit
DATA
fi
}
function ejabberd_report_processes() { function ejabberd_report_processes() {
local limit=$(ejabberd_exec 'erlang:system_info(process_limit).') local limit=$(ejabberd_exec 'erlang:system_info(process_limit).')
if [ "$1" = "config" ]; then if [ "$1" = "config" ]; then
@ -217,6 +245,7 @@ ports
online_users online_users
registered_users registered_users
SUGGESTIONS SUGGESTIONS
open_files_counter_util &>/dev/null && echo open_files
exit 0 exit 0
;; ;;
config) config)