From bf9c3caae930e466c603d9ed97024c36ef5d652a Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Fri, 15 Nov 2013 23:46:37 +0300 Subject: [PATCH] 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. --- .../ejabberd_resources_/ejabberd_resources_ | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ index 43d6ed27..f725183d 100755 --- a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ +++ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ @@ -14,6 +14,7 @@ # - connect to a running ejabberd node # # OS: *NIX +# Requires lsof/fstat for open_files. # # Author: Artem Sheremet # @@ -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. INFO_FROM_DOC else - pid=$(<$EJABBERD_PID_PATH) + local 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 @@ -140,42 +141,69 @@ 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 </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 </dev/null && echo open_files exit 0 ;; config)