xmpp/metrology/collectd_exec_xmpp.sh

35 lines
1.5 KiB
Bash
Raw Normal View History

HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL="${COLLECTD_INTERVAL:-60}"
# required by some ejabberdctl commands
export HOME=/var/lib/ejabberd
export HTTP_UPLOAD_DATADIR="/var/www/xmpp.chapril.org/upload/"
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)"
}
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