Better sql request to count IRC active/inactive users

This commit is contained in:
Adrien Bourmault 2021-02-13 17:54:48 +01:00 committed by root
parent 0cb00d90d8
commit 871289dd04

View File

@ -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}'
}