From b518af0f693c0128259ee69e051c70e1776a20d7 Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Mon, 9 Mar 2015 10:33:42 +0100 Subject: [PATCH] ejabberd_resources: add mnesia table info support --- .../ejabberd_resources_/ejabberd_resources_ | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ index 57394510..4621a5e7 100755 --- a/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ +++ b/plugins/ejabberd/ejabberd_resources_/ejabberd_resources_ @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# ejabberd_resources_ revision 3 (Nov 2013) +# ejabberd_resources_ revision 4 (Mar 2015) # # Tested with ejabberd 2.1.x # @@ -8,6 +8,7 @@ # - ejabberd memory usage (RSS, VSZ, erlang internal) # - ejabberd ports/processes usage # - online/registered users by vhost +# - mnesia table sizes and location # # Required permissions: # - read ejabberdctl configuration file @@ -19,9 +20,10 @@ # Author: Artem Sheremet # # Configuration: -# - set env.ejabberdctl_cfg to ejabberdctl.cfg path if necessary +# - set env.ejabberdctl_cfg to ejabberdctl.cfg path if not in /etc # - or set env.ERLANG_NODE, env.EJABBERD_PID_PATH to proper values manually # - set erl_call_path to unregular erl_call location +# - set env.ejabberdctl to ejabberdctl script path if not on PATH #%# family=auto #%# capabilities=autoconf suggest @@ -30,6 +32,8 @@ EJABBERDCTL_CFG=${ejabberdctl_cfg:-/etc/ejabberd/ejabberdctl.cfg} source $EJABBERDCTL_CFG 2>/dev/null source $MUNIN_LIBDIR/plugins/plugin.sh +EJABBERDCTL=${ejabberdctl:-$(which ejabberdctl)} + ERLANG_HOST=${ERLANG_NODE/*@/} ERLANG_MUNIN_NODE=munin @@ -155,6 +159,53 @@ DATA fi } +function ejabberd_report_mnesia() { + local draw sed_re long_bits + + sed_re='([a-z_]+) *: with ([0-9]+) +records occupying ([0-9]+) +([a-z]+) o[fn] ([a-z]+)' + # 1 = table_name + # 2 = records number + # 3 = bytes/words number + # 4 = unit (bytes or words) + # 5 = storage (disc or mem) + + if [ "$1" = config ]; then + echo "graph_vlabel $2" + draw=LINE2 + [ "$2" = bytes ] && draw=AREASTACK + + $EJABBERDCTL mnesia info | sed -re 's/'"$sed_re"'/\1 \5/;tx;d;:x' | + while read table_name table_storage; do + echo "${table_name}_${table_storage}.draw $draw" + echo "${table_name}_${table_storage}.label $table_name ($table_storage)" + done + else + if [ "$2" = recs ]; then + $EJABBERDCTL mnesia info | sed -re 's/'"$sed_re"'/\1_\5.value \2/;tx;d;:x' + else + long_bits=$(getconf LONG_BIT) + $EJABBERDCTL mnesia info | + sed -re 's/'"$sed_re"'/\1_\5.value \3 \4/;tx;d;:x' | + awk " + / words\$/ { + print \$1, \$2 * $long_bits / 8 + } + / bytes\$/ { + print \$1, \$2 + } + " + fi + fi +} + +function ejabberd_report_mnesia_bytes() { + ejabberd_report_mnesia "$1" bytes +} + +function ejabberd_report_mnesia_recs() { + ejabberd_report_mnesia "$1" recs +} + function open_files_counter_util() { if hash lsof &>/dev/null; then echo lsof @@ -232,6 +283,8 @@ processes ports online_users registered_users +mnesia_recs +mnesia_bytes SUGGESTIONS open_files_counter_util &>/dev/null && echo open_files exit 0