From 871289dd04f4fbfa7603d1c03fa8a0959f7ef6ca Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sat, 13 Feb 2021 17:54:48 +0100 Subject: [PATCH] Better sql request to count IRC active/inactive users --- rapport_activite/rapport_activites.sh | 48 ++++++++++++++++++++------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/rapport_activite/rapport_activites.sh b/rapport_activite/rapport_activites.sh index 202fa33..fc41ebf 100755 --- a/rapport_activite/rapport_activites.sh +++ b/rapport_activite/rapport_activites.sh @@ -26,7 +26,7 @@ main() { echo "" echo "h2. ## Audio/Video Call usage:" echo "" - echo "* Number of calls relayed: $(zgrep "$DATE" /var/log/ejabberd/ejabberd.log* | grep -i -e "Offering stun" | wc -l)" + echo "* Total calls relayed: $(zgrep "$DATE" /var/log/ejabberd/ejabberd.log* | grep -i -e "Offering stun" | wc -l)" 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" @@ -110,10 +110,16 @@ count_biboumi_users() { } count_biboumi_active_users() { - since=${1:-'1 MONTH'} + since=${1:-'1 MONTH'} sql="select count(distinct owner_) - from muclogline_ - where to_timestamp(date_) > current_timestamp - interval '${since}'" + from ( + select owner_,date_ + from muclogline_ as m1 + where date_ = ( + select max(date_) + from muclogline_ as m2 + where m2.owner_ = m1.owner_ ) ) as m0 + where to_timestamp(m0.date_) > current_timestamp - interval '${since}'" sudo -Hiu postgres psql biboumi -c "${sql}" -t | grep -v '^$' | awk '{print $1}' } @@ -121,9 +127,15 @@ count_biboumi_active_users() { count_biboumi_active_external_users() { since=${1:-'1 MONTH'} sql="select count(distinct owner_) - from muclogline_ - where muclogline_.owner_ not like '%chapril.org%' - and to_timestamp(date_) > current_timestamp - interval '${since}'" + from ( + select owner_,date_ + from muclogline_ as m1 + where date_ = ( + select max(date_) + from muclogline_ as m2 + where m2.owner_ = m1.owner_ ) ) as m0 + where to_timestamp(m0.date_) > current_timestamp - interval '${since}' + and m0.owner_ not like '%chapril.org%'" sudo -Hiu postgres psql biboumi -c "${sql}" -t | grep -v '^$' | awk '{print $1}' } @@ -131,8 +143,14 @@ count_biboumi_active_external_users() { count_biboumi_inactive_users() { since=${1:-'1 MONTH'} sql="select count(distinct owner_) - from muclogline_ - where to_timestamp(date_) < current_timestamp - interval '${since}'" + from ( + select owner_,date_ + from muclogline_ as m1 + where date_ = ( + select max(date_) + from muclogline_ as m2 + where m2.owner_ = m1.owner_ ) ) as m0 + where to_timestamp(m0.date_) < current_timestamp - interval '${since}'" sudo -Hiu postgres psql biboumi -c "${sql}" -t | grep -v '^$' | awk '{print $1}' } @@ -140,9 +158,15 @@ count_biboumi_inactive_users() { count_biboumi_inactive_external_users() { since=${1:-'1 MONTH'} sql="select count(distinct owner_) - from muclogline_ - where muclogline_.owner_ not like '%chapril.org%' - and to_timestamp(date_) < current_timestamp - interval '${since}'" + from ( + select owner_,date_ + from muclogline_ as m1 + where date_ = ( + select max(date_) + from muclogline_ as m2 + where m2.owner_ = m1.owner_ ) ) as m0 + where to_timestamp(m0.date_) < current_timestamp - interval '${since}' + and m0.owner_ not like '%chapril.org%'" sudo -Hiu postgres psql biboumi -c "${sql}" -t | grep -v '^$' | awk '{print $1}' }