From e951c34796c06eae560748814983bf1c78d8aa13 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 13 Dec 2020 22:47:07 +0100 Subject: [PATCH] More precise time window for stats --- rapport_activite/rapport_activites.sh | 90 ++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/rapport_activite/rapport_activites.sh b/rapport_activite/rapport_activites.sh index 60b8a56..6b51d99 100755 --- a/rapport_activite/rapport_activites.sh +++ b/rapport_activite/rapport_activites.sh @@ -2,7 +2,7 @@ STORAGE_DIR="/var/www/xmpp.chapril.org/upload/" -main() { +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)" @@ -22,11 +22,13 @@ main() { echo "* Total disk usage: $(du -sh ${STORAGE_DIR} | awk '{print $1}')" per_account_storage_usage + DATE=$(get_last_month) echo "" echo "h2. ## Audio/Video Call usage:" # Dans la config actuelle de logrotate, le log du mois dernier est stocké en tete clair, et tous les autres sont compressés par gzip. Un cat ne sortira de texte lisible que pour les fichiers en clair soit forcément celui du mois précédent echo "" - echo "* Number of calls relayed: $(ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Offering stun" | wc -l)" + echo "* Number of calls relayed: $(zgrep DATE /var/log/ejabberd/ejabberd.log* | grep -i -e "Offering stun" | wc -l)" + get_avg_UDP_turn_relayed_data 12 echo "* Data relayed per protocol per call:" echo "** UDP: avg $(get_avg_UDP_turn_relayed_data) KiB, max $(get_max_UDP_turn_relayed_data) KiB, total $(get_total_UDP_turn_relayed_data) KiB" echo "** TCP: avg $(get_avg_TCP_turn_relayed_data) KiB, max $(get_max_TCP_turn_relayed_data) KiB, total $(get_total_TCP_turn_relayed_data) KiB" @@ -93,49 +95,105 @@ 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}' } -get_stunstats_from_log() { - ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Offering stun" +get_last_month() { + if [ "$(date +%m)" -gt 1 ]; then + precedingMonth="$((10#$(date +%m)-1))" + year="$(date +%Y)" + if [ $precedingMonth -lt 10 ]; then + yearMonth="$year-0$precedingMonth" + else + yearMonth="$year-$precedingMonth" + fi + else [ "$(date +%m)" -eq 1 ] + precedingMonth=12 + year="$(($(date +%Y)-1))" + yearMonth="$year-$precedingMonth" + fi + echo "$year-$precedingMonth" } + get_total_UDP_turn_relayed_data() { - ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "UDP" | cut -d" " -f6-6 | paste -sd+ - | bc + n=$(zgrep $DATE /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "UDP" | cut -d" " -f6-6 | paste -sd+ - | bc) + if [ -z $n ]; then + echo 0 + else + echo $n + fi } get_total_TCP_turn_relayed_data() { - ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "TCP" | cut -d" " -f6-6 | paste -sd+ - | bc + n=$(zgrep $DATE /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TCP" | cut -d" " -f6-6 | paste -sd+ - | bc) + if [ -z $n ]; then + echo 0 + else + echo $n + fi } get_total_TLS_turn_relayed_data() { - ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "TLS" | cut -d" " -f6-6 | paste -sd+ - | bc + n=$(zgrep $DATE /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TLS" | cut -d" " -f6-6 | paste -sd+ - | bc) + if [ -z $n ]; then + echo 0 + else + echo $n + fi } get_max_UDP_turn_relayed_data() { - ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "UDP" | cut -d" " -f6-6 | sort | tail -n 1 + n=$(zgrep $DATE /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "UDP" | cut -d" " -f6-6 | sort | tail -n 1) + if [ -z $n ]; then + echo 0 + else + echo $n + fi } get_max_TCP_turn_relayed_data() { - ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "TCP" | cut -d" " -f6-6 | sort | tail -n 1 + n=$(zgrep $DATE /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TCP" | cut -d" " -f6-6 | sort | tail -n 1) + if [ -z $n ]; then + echo 0 + else + echo $n + fi } get_max_TLS_turn_relayed_data() { - ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "TLS" | cut -d" " -f6-6 | paste -sd+ - | sort | tail -n 1 + n=$(zgrep $DATE /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TLS" | cut -d" " -f6-6 | sort | tail -n 1) + if [ -z $n ]; then + echo 0 + else + echo $n + fi } get_avg_UDP_turn_relayed_data() { - num=$(ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "UDP" | wc -l) + n=$(zgrep "$DATE" /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "UDP" | wc -l) total=$(get_total_UDP_turn_relayed_data) - echo "scale=2; $total / $num" | bc -l + if [ $n -eq 0 ]; then + echo 0 + else + echo "scale=2; $total / $n" | bc -l + fi } get_avg_TCP_turn_relayed_data() { - num=$(ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "TCP" | wc -l) + n=$(zgrep "$DATE" /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TCP" | wc -l) total=$(get_total_TCP_turn_relayed_data) - echo "scale=2; $total / $num" | bc -l + if [ $n -eq 0 ]; then + echo 0 + else + echo "scale=2; $total / $n" | bc -l + fi } get_avg_TLS_turn_relayed_data() { - num=$(ls -1tr /var/log/ejabberd/ejabberd.log* | tail -n 5 | xargs zcat -f | grep -i -e "Relayed" | grep "TLS" | wc -l) + n=$(zgrep "$DATE" /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TLS" | wc -l) total=$(get_total_TLS_turn_relayed_data) - echo "scale=2; $total / $num" | bc -l + if [ $n -eq 0 ]; then + echo 0 + else + echo "scale=2; $total / $n" | bc -l + fi } main