From 098fc2e302a76119176f512f55ab1872d81fbdb5 Mon Sep 17 00:00:00 2001 From: pitchum Date: Sun, 18 Apr 2021 12:25:43 +0200 Subject: [PATCH] Add metrology: total number of room occupants --- metrology/collectd_exec_xmpp.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/metrology/collectd_exec_xmpp.sh b/metrology/collectd_exec_xmpp.sh index a69350a..511635f 100755 --- a/metrology/collectd_exec_xmpp.sh +++ b/metrology/collectd_exec_xmpp.sh @@ -26,6 +26,7 @@ ejabberdctl_stats() { echo "PUTVAL \"${HOSTNAME}/xmpp_muc_total/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl muc_online_rooms muc.chapril.org | wc -l)" echo "PUTVAL \"${HOSTNAME}/xmpp_accounts_created_lastday/count\" interval=$INTERVAL $(date +%s):$(count_accounts_created_lastday)" + echo -n "PUTVAL \"${HOSTNAME}/xmpp_public_rooms_occupants/count\" interval=$INTERVAL $(date +%s):" ; _xmpp_public_rooms_total_occupants } http_upload_disk_usage() { @@ -48,6 +49,29 @@ count_accounts_created_lastday() { " } +_xmpp_public_rooms_total_occupants() { + # keep results in a cache file for 5 minutes + local cache_file=/var/tmp/cache_collectd_xmpp_rooms.data + if [ ! -f ${cache_file} -o "$(find ${cache_file} -mmin +5 2>/dev/null)" ]; then + _xmpp_list_public_rooms > ${cache_file} + fi + total_occupants=0 + while read line; do + total_occupants=$((total_occupants+$(echo ${line} | awk '{print $2}'))) + done < ${cache_file} + echo ${total_occupants} +} + +_xmpp_list_public_rooms() { + for room in $(ejabberdctl muc_online_rooms muc.chapril.org | cut -d@ -f1) ; do + if ejabberdctl get_room_options ${room} muc.chapril.org | egrep -q '^public\s*true' ; then + echo -n "${room}: " + ejabberdctl get_room_occupants ${room} muc.chapril.org | cut -d@ -f1 | sort -u | wc -l + fi + done | sort -k 2 -nr +} + + _sql_ejabberd() { # XXX the psql command can only works if file /var/lib/ejabberd/.pgpass exists psql -U ejabberd -h localhost ejabberd -c "${1}" -t | grep -v '^$' | awk '{print $1}'