From 3106172e85d6dec73b4b24ddffc8d3ff38aa2aa2 Mon Sep 17 00:00:00 2001 From: pitchum Date: Mon, 15 Mar 2021 20:18:49 +0100 Subject: [PATCH] Add metrology for http_upload disk usage --- metrology/collectd_exec_xmpp.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/metrology/collectd_exec_xmpp.sh b/metrology/collectd_exec_xmpp.sh index a91523a..636b95d 100755 --- a/metrology/collectd_exec_xmpp.sh +++ b/metrology/collectd_exec_xmpp.sh @@ -3,12 +3,32 @@ INTERVAL="${COLLECTD_INTERVAL:-60}" # required by some ejabberdctl commands export HOME=/var/lib/ejabberd +export HTTP_UPLOAD_DATADIR="/var/www/xmpp.chapril.org/upload/" -while sleep "$INTERVAL"; do + +main() { + # do-while hack found here: https://stackoverflow.com/questions/24420342/is-there-a-do-while-loop-in-bash#24421013 + while + ejabberdctl_stats + http_upload_disk_usage + sleep "$INTERVAL" + do true; done +} + +ejabberdctl_stats() { echo "PUTVAL \"${HOSTNAME}/xmpp_registered_users/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl registered_users chapril.org | wc -l)" echo "PUTVAL \"${HOSTNAME}/xmpp_active_users/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl connected_users_number)" echo "PUTVAL \"${HOSTNAME}/xmpp_s2s_in/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl incoming_s2s_number)" echo "PUTVAL \"${HOSTNAME}/xmpp_s2s_out/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl outgoing_s2s_number)" echo "PUTVAL \"${HOSTNAME}/xmpp_muc_total/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl muc_online_rooms muc.chapril.org | wc -l)" -done +} +http_upload_disk_usage() { + subfolders_count=$(find ${HTTP_UPLOAD_DATADIR} -mindepth 1 -maxdepth 1 -type d | wc -l) + total_size=$(du -s ${HTTP_UPLOAD_DATADIR} | awk '{print $1}') + avg=$(( ${total_size} / ${subfolders_count} )) + echo "PUTVAL \"${HOSTNAME}/xmpp_upload_data_total/count\" interval=$INTERVAL $(date +%s):${total_size}" + echo "PUTVAL \"${HOSTNAME}/xmpp_upload_data_avg/count\" interval=$INTERVAL $(date +%s):${avg}" +} + +main