Add metrology: total number of room occupants
This commit is contained in:
parent
dc7484e16a
commit
098fc2e302
@ -26,6 +26,7 @@ ejabberdctl_stats() {
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_muc_total/count\" interval=$INTERVAL $(date +%s):$(ejabberdctl muc_online_rooms muc.chapril.org | wc -l)"
|
||||
|
||||
echo "PUTVAL \"${HOSTNAME}/xmpp_accounts_created_lastday/count\" interval=$INTERVAL $(date +%s):$(count_accounts_created_lastday)"
|
||||
echo -n "PUTVAL \"${HOSTNAME}/xmpp_public_rooms_occupants/count\" interval=$INTERVAL $(date +%s):" ; _xmpp_public_rooms_total_occupants
|
||||
}
|
||||
|
||||
http_upload_disk_usage() {
|
||||
@ -48,6 +49,29 @@ count_accounts_created_lastday() {
|
||||
"
|
||||
}
|
||||
|
||||
_xmpp_public_rooms_total_occupants() {
|
||||
# keep results in a cache file for 5 minutes
|
||||
local cache_file=/var/tmp/cache_collectd_xmpp_rooms.data
|
||||
if [ ! -f ${cache_file} -o "$(find ${cache_file} -mmin +5 2>/dev/null)" ]; then
|
||||
_xmpp_list_public_rooms > ${cache_file}
|
||||
fi
|
||||
total_occupants=0
|
||||
while read line; do
|
||||
total_occupants=$((total_occupants+$(echo ${line} | awk '{print $2}')))
|
||||
done < ${cache_file}
|
||||
echo ${total_occupants}
|
||||
}
|
||||
|
||||
_xmpp_list_public_rooms() {
|
||||
for room in $(ejabberdctl muc_online_rooms muc.chapril.org | cut -d@ -f1) ; do
|
||||
if ejabberdctl get_room_options ${room} muc.chapril.org | egrep -q '^public\s*true' ; then
|
||||
echo -n "${room}: "
|
||||
ejabberdctl get_room_occupants ${room} muc.chapril.org | cut -d@ -f1 | sort -u | wc -l
|
||||
fi
|
||||
done | sort -k 2 -nr
|
||||
}
|
||||
|
||||
|
||||
_sql_ejabberd() {
|
||||
# XXX the psql command can only works if file /var/lib/ejabberd/.pgpass exists
|
||||
psql -U ejabberd -h localhost ejabberd -c "${1}" -t | grep -v '^$' | awk '{print $1}'
|
||||
|
Loading…
Reference in New Issue
Block a user