Add stats about user-agents

This commit is contained in:
pitchum 2024-09-21 15:09:57 +02:00 committed by root
parent 2499c291c3
commit d2a005ebbd

View File

@ -1,3 +1,5 @@
#!/bin/bash
HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL="${COLLECTD_INTERVAL:-60}"
@ -12,7 +14,7 @@ main() {
ejabberdctl_stats
http_upload_disk_usage
captcha_stats
#client_stats # XXX pas encore activée
_useragents_stats
sleep "$INTERVAL"
do true; done
}
@ -100,17 +102,68 @@ _sql_ejabberd() {
psql -U ejabberd -h localhost ejabberd -c "${1}" -t | grep -v '^$' | awk '{print $1}'
}
# XXX la syntaxe de la boucle while ci-dessous fait échouer le démarrage de collectd.
# exec plugin: exec_read_one: error = /srv/xmpp.chapril.org/tools/metrology/collectd_exec_xmpp.sh: 44: /srv/xmpp.chapril.org/tools/metrology/collectd_exec_xmpp.sh: Syntax error: redirection unexpected
#client_stats(){
# return 0
# # Fonction pas encore activée car je n'aime pas l'idée de créer dans influxdb autant de noms de métriques que de clients XMPP.
# # Il faut encore étudier le format d'envoi de collectd.
# while read -r line ; do
# clientname=$(echo ${line} | awk '{print $2}')
# count=$(echo ${line} | awk '{print $1}')
# echo "PUTVAL \"${HOSTNAME}/xmpp_client_${clientname}/count\" interval=$INTERVAL $(date +%s):${count}"
# done < <(ejabberdctl connected_users | sed -r 's;^.*@chapril.org/([^. -]+).*;\1;' | sort | uniq -c | sort -n)
#}
_useragents_stats() {
declare -A counters
items="$(ejabberdctl connected_users_info | sed -r 's/^(.*)\s+c2s_.*/\1/g' | cut -d/ -f2- | sed -r 's/\s+/_/g' )"
for line in $items; do
if echo ${line} | grep -qEi gajim ; then
ua=gajim
elif echo ${line} | grep -qEi dino ; then
ua=dino
elif echo ${line} | grep -qEi profanity ; then
ua=profanity
elif echo ${line} | grep -qEi conversations ; then
ua=conversations
elif echo ${line} | grep -qEi blabber ; then
ua=blabber
elif echo ${line} | grep -qEi cheogram ; then
ua=cheogram
elif echo ${line} | grep -qEi monocles ; then
ua=monocles
elif echo ${line} | grep -qEi monal ; then
ua=monal
elif echo ${line} | grep -qEi snikket ; then
ua=snikket
elif echo ${line} | grep -qEi movim ; then
ua=movim
elif echo ${line} | grep -qEi converse ; then
ua=converse
elif echo ${line} | grep -qEi unichat ; then
ua=unichat
elif echo ${line} | grep -qEi "poezio" ; then
ua=poezio
elif echo ${line} | grep -qEi mcabber ; then
ua=mcabber
elif echo ${line} | grep -qEi c0nnect ; then
ua=c0nnect
elif echo ${line} | grep -qEi "pix-art" ; then
ua=pix-art
elif echo ${line} | grep -qEi "bitlbee" ; then
ua=bitlbee
elif echo ${line} | grep -qEi "(pidgin|gaim)" ; then
ua=pidgin
elif echo ${line} | grep -qEi "^[0-9]{21,26}" ; then
ua=pidgin-probably
elif echo ${line} | grep -qEi "macbook" ; then
ua=mac-computer
elif echo ${line} | grep -qEi "imac-de" ; then
ua=mac-computer
else
ua=other
fi
k=${counters[$ua]:-0}
((k++))
counters[$ua]=$k
done
ts=$(date +%s)
for i in "${!counters[@]}"; do
ua=$i
count=${counters[$i]}
echo "PUTVAL \"${HOSTNAME}/xmpp_useragent/count-${ua}\" interval=${INTERVAL} ${ts}:${count}"
done
}
main