2020-03-17 20:27:40 +01:00
#! /bin/bash
2020-11-10 19:29:47 +01:00
STORAGE_DIR = "/var/www/xmpp.chapril.org/upload/"
2020-12-13 22:47:07 +01:00
main( ) {
2020-03-17 20:27:40 +01:00
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) "
2020-11-18 15:24:14 +01:00
echo " ** Active: $( count_active_accounts) "
echo " ** Inactive: $( count_inactive_accounts '1 MONTH' ) "
echo " ** Removable: $( count_removable_accounts '6 MONTHS' ) "
2020-03-17 20:27:40 +01:00
echo " * Total messages stored (MAM): $( count_archived_messages) "
2020-03-17 20:38:47 +01:00
echo " * Total rooms active: $( sudo -u ejabberd ejabberdctl muc_online_rooms global | wc -l) "
2020-11-18 15:24:14 +01:00
echo ""
echo "_* Inactive accounts:_ no connection during last month"
echo "_* Removable accounts:_ no connection in the last 6 months *and* didn't read the welcome message"
2020-03-17 20:27:40 +01:00
echo ""
echo "h2. ## HTTP upload storage:"
echo ""
echo " * User quota: $( get_hard_quota) M "
2020-11-10 19:29:47 +01:00
echo " * Total disk usage: $( du -sh ${ STORAGE_DIR } | awk '{print $1}' ) "
2020-03-17 20:27:40 +01:00
per_account_storage_usage
2020-12-08 12:32:01 +01:00
2020-12-13 22:47:07 +01:00
DATE = $( get_last_month)
2020-12-08 12:32:01 +01:00
echo ""
echo "h2. ## Audio/Video Call usage:"
echo ""
2021-02-13 17:54:48 +01:00
echo " * Total calls relayed: $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Offering stun" | wc -l) "
2020-12-13 13:46:13 +01:00
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 "
echo " ** TLS: avg $( get_avg_TLS_turn_relayed_data) KiB, max $( get_max_TLS_turn_relayed_data) KiB, total $( get_total_TLS_turn_relayed_data) KiB "
2021-02-08 20:31:02 +01:00
echo ""
echo "h2. ## XMPP/IRC Bridge (Biboumi) usage:"
echo ""
echo " * Total channels active: $( count_biboumi_active_chan) "
echo " ** through $( count_biboumi_active_servers) IRC server(s) "
2021-02-11 20:41:33 +01:00
echo " * Total users: $( count_biboumi_users) "
echo " ** Active: $( count_biboumi_active_users '1 MONTH' ) (External accounts: $( count_biboumi_active_external_users '1 MONTH' ) ) "
echo " ** Inactive: $( count_biboumi_inactive_users '1 MONTH' ) (External accounts: $( count_biboumi_inactive_external_users '1 MONTH' ) ) "
echo " * Total messages stored (MAM): $( count_biboumi_archived_messages) "
2020-03-17 20:27:40 +01:00
}
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( ) {
# 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 "
}
2020-11-18 15:24:14 +01:00
count_active_accounts( ) {
since = ${ 1 :- '1 MONTH' }
sql = " select count(distinct l.username)
from last l
join users u on l.username = u.username
where to_timestamp( cast( l.seconds as int) ) > current_timestamp - interval '${since}'
and l.username not in ( 'r.giskard' , 'lisa.simpson' , 'bart.simpson' ) "
psql -U ejabberd -h localhost ejabberd -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
count_inactive_accounts( ) {
since = ${ 1 :- '1 MONTH' }
sql = " select count(distinct l.username)
from last l
join users u on l.username = u.username
where to_timestamp( cast( l.seconds as int) ) < current_timestamp - interval '${since}'
and l.username not in ( 'r.giskard' , 'lisa.simpson' , 'bart.simpson' ) "
psql -U ejabberd -h localhost ejabberd -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
count_removable_accounts( ) {
# Accounts inactive *and* who never read the welcome message.
since = ${ 1 :- '6 MONTHS' }
sql = " select count(distinct l.username)
from last l
join users u on l.username = u.username
join spool s on l.username = s.username
where to_timestamp( cast( l.seconds as int) ) < current_timestamp - interval '${since}'
and s.xml like '%from=' 'chapril.org' ' xmlns=' 'jabber:client' '%Bienvenue sur le serveur%'
and s.username not in ( 'r.giskard' , 'lisa.simpson' , 'bart.simpson' ) "
psql -U ejabberd -h localhost ejabberd -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
2020-03-17 20:27:40 +01:00
count_archived_messages( ) {
2021-02-11 20:41:33 +01:00
sudo -Hiu postgres psql 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}'
2021-02-08 20:31:02 +01:00
}
count_biboumi_users( ) {
sql = " select count(distinct owner_)
from muclogline_"
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
count_biboumi_active_users( ) {
2021-02-13 17:54:48 +01:00
since = ${ 1 :- '1 MONTH' }
2021-02-08 20:31:02 +01:00
sql = " select count(distinct owner_)
2021-02-13 17:54:48 +01:00
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}' "
2021-02-08 20:31:02 +01:00
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
2021-02-11 20:41:33 +01:00
count_biboumi_active_external_users( ) {
since = ${ 1 :- '1 MONTH' }
sql = " select count(distinct owner_)
2021-02-13 17:54:48 +01:00
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%' "
2021-02-11 20:41:33 +01:00
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
2021-02-08 20:31:02 +01:00
count_biboumi_inactive_users( ) {
since = ${ 1 :- '1 MONTH' }
sql = " select count(distinct owner_)
2021-02-13 17:54:48 +01:00
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}' "
2021-02-08 20:31:02 +01:00
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
2021-02-11 20:41:33 +01:00
count_biboumi_inactive_external_users( ) {
since = ${ 1 :- '1 MONTH' }
sql = " select count(distinct owner_)
2021-02-13 17:54:48 +01:00
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%' "
2021-02-11 20:41:33 +01:00
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
2021-02-08 20:31:02 +01:00
count_biboumi_archived_messages( ) {
since = ${ 1 :- '1 MONTH' }
2021-02-11 20:41:33 +01:00
sql = " select count(body_)
2021-02-08 20:31:02 +01:00
from muclogline_"
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
count_biboumi_active_servers( ) {
since = ${ 1 :- '1 MONTH' }
sql = " select count(distinct ircservername_)
from muclogline_
where to_timestamp( date_) > current_timestamp - interval '${since}' "
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
}
count_biboumi_active_chan( ) {
since = ${ 1 :- '1 MONTH' }
sql = " select count(distinct ircchanname_)
from muclogline_
where to_timestamp( date_) > current_timestamp - interval '${since}' "
sudo -Hiu postgres psql biboumi -c " ${ sql } " -t | grep -v '^$' | awk '{print $1}'
2020-03-17 20:27:40 +01:00
}
2020-12-13 22:47:07 +01:00
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
2021-02-01 12:05:11 +01:00
echo $yearMonth
2020-12-13 13:46:13 +01:00
}
2020-12-13 22:47:07 +01:00
2020-12-08 12:32:01 +01:00
get_total_UDP_turn_relayed_data( ) {
2021-01-01 15:12:21 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "UDP" | cut -d" " -f6-6 | paste -sd+ - | bc)
2020-12-13 22:47:07 +01:00
if [ -z $n ] ; then
echo 0
else
echo $n
fi
2020-12-08 12:32:01 +01:00
}
get_total_TCP_turn_relayed_data( ) {
2021-01-01 15:12:21 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TCP" | cut -d" " -f6-6 | paste -sd+ - | bc)
2020-12-13 22:47:07 +01:00
if [ -z $n ] ; then
echo 0
else
echo $n
fi
2020-12-08 12:32:01 +01:00
}
get_total_TLS_turn_relayed_data( ) {
2021-01-01 15:12:21 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TLS" | cut -d" " -f6-6 | paste -sd+ - | bc)
2020-12-13 22:47:07 +01:00
if [ -z $n ] ; then
echo 0
else
echo $n
fi
2020-12-13 13:46:13 +01:00
}
get_max_UDP_turn_relayed_data( ) {
2021-02-01 12:25:32 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "UDP" | cut -d" " -f6-6 | sort -g | tail -n 1)
2020-12-13 22:47:07 +01:00
if [ -z $n ] ; then
echo 0
else
echo $n
fi
2020-12-13 13:46:13 +01:00
}
get_max_TCP_turn_relayed_data( ) {
2021-02-01 12:25:32 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TCP" | cut -d" " -f6-6 | sort -g | tail -n 1)
2020-12-13 22:47:07 +01:00
if [ -z $n ] ; then
echo 0
else
echo $n
fi
2020-12-13 13:46:13 +01:00
}
get_max_TLS_turn_relayed_data( ) {
2021-02-01 12:25:32 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TLS" | cut -d" " -f6-6 | sort -g | tail -n 1)
2020-12-13 22:47:07 +01:00
if [ -z $n ] ; then
echo 0
else
echo $n
fi
2020-12-08 12:32:01 +01:00
}
get_avg_UDP_turn_relayed_data( ) {
2020-12-13 22:47:07 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "UDP" | wc -l)
2020-12-08 12:32:01 +01:00
total = $( get_total_UDP_turn_relayed_data)
2020-12-13 22:47:07 +01:00
if [ $n -eq 0 ] ; then
echo 0
else
echo " scale=2; $total / $n " | bc -l
fi
2020-12-08 12:32:01 +01:00
}
get_avg_TCP_turn_relayed_data( ) {
2020-12-13 22:47:07 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TCP" | wc -l)
2020-12-08 12:32:01 +01:00
total = $( get_total_TCP_turn_relayed_data)
2020-12-13 22:47:07 +01:00
if [ $n -eq 0 ] ; then
echo 0
else
echo " scale=2; $total / $n " | bc -l
fi
2020-12-08 12:32:01 +01:00
}
get_avg_TLS_turn_relayed_data( ) {
2020-12-13 22:47:07 +01:00
n = $( zgrep " $DATE " /var/log/ejabberd/ejabberd.log* | grep -i -e "Relayed" | grep "TLS" | wc -l)
2020-12-08 12:32:01 +01:00
total = $( get_total_TLS_turn_relayed_data)
2020-12-13 22:47:07 +01:00
if [ $n -eq 0 ] ; then
echo 0
else
echo " scale=2; $total / $n " | bc -l
fi
2020-12-08 12:32:01 +01:00
}
2020-03-17 20:27:40 +01:00
main