xmpp/rapport_activite/rapport_activites.sh

44 lines
1.8 KiB
Bash
Executable File

#! /bin/bash
main() {
echo "h2. ## Global info"
echo ""
echo "* Total accounts: $(sudo -u ejabberd ejabberdctl registered_users chapril.org | egrep -v -e 'r\.giskard' -e '(lisa|bart)\.simpson' | wc -l)"
echo "* Total messages stored (MAM): $(count_archived_messages) "
# echo "Active users: $(sudo -u ejabberd ejabberdctl connected_users_number)"
echo ""
echo "h2. ## HTTP upload storage:"
echo ""
echo "* User quota: $(get_hard_quota)M"
echo "* Total disk usage: $(du -sh /srv/ejabberd/chapril.org/upload/ | awk '{print $1}')"
per_account_storage_usage
# echo "s2s outgoing connections: $(sudo -u ejabberd ejabberdctl incoming_s2s_number)"
# echo "s2s incoming connections: $(sudo -u ejabberd ejabberdctl outgoing_s2s_number)"
}
get_hard_quota() {
grep hard_quota /etc/ejabberd/ejabberd.yml -A2 | grep all | sed -r 's/^\s*-\s([0-9]+).*/\1/'
}
per_account_storage_usage() {
STORAGE_DIR="/srv/ejabberd/chapril.org/upload/"
# TODO Directories to ignore because they are used for tests accounts (bart and lisa simpsons)
IGNORE_DIRS="35eae3ddc83d72e4d3fad3160a400db688d7d936 9be859c77649f33d207cbe0d74a126b2fd31cb33"
echo "Per user disk usage:"
tmp="$(du -sh ${STORAGE_DIR}* | sort -hr | awk '{print $1}')"
echo "** Max: "$(echo "${tmp}" | head -n 1)
# echo " Min: "$(echo "${tmp}" | tail -n 1)
subfolders_count=$(find ${STORAGE_DIR} -mindepth 1 -maxdepth 1 -type d | wc -l)
total_size=$(du -s ${STORAGE_DIR} | awk '{print $1}')
avg=$(((${total_size} / 1024) / ${subfolders_count}))
echo "** Avg: ${avg}M"
}
count_archived_messages() {
psql -U ejabberd -h localhost ejabberd -c "select count(*) from archive where peer not like 'irc%' and username not in ('r.giskard', 'lisa.simpson', 'bart.simpson')" -t | grep -v '^$' | awk '{print $1}'
}
main