minetest.chapril.org-tools/rapport_activite/rapport_activite_mineclone2.sh

133 lines
5.6 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# Copyright (C) 2018,2019 Didier Clermonté <dclermonte@april.org>
# Copyright (C) 2018,2019 Christian Pierre Momon <christian.momon@devinsy.fr>
# 2023 Adapt from date.charil.org to minetest.chapril.org
#
# This file is part of minetest.chapril.org.
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ============================================
help()
{
echo "Usage:"
echo " $(basename "$0") -h display help"
echo " $(basename "$0") analyse current month"
echo " $(basename "$0") -p analyse preceding month"
echo " $(basename "$0") month_number year analyse this month"
}
generateReport()
{
local monthEnglish="$1"
local month="$2"
local year="$3"
echo -e "================================================================="
echo
connectionCount=$(zgrep " joins game" /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de connexions à Mineclone2 = $connectionCount"
uniqConnectionCount=$(zgrep " joins game" /var/log/minetest/30009-mineclone2.log-${month}* | uniq | wc -l)
echo "Nombre de connexions \"uniques\" à Mineclone2 = $uniqConnectionCount"
voxelPut=$(zgrep " places node " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de blocs posés = $voxelPut"
voxelDug=$(zgrep " digs " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de blocs creusés = $voxelDug"
voxelCrafted=$(zgrep " crafts " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre d'objets créés = $voxelCrafted"
awardsGot=$(zgrep " has gotten award " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de haut-faits débloqué = $awardsGot"
deadCount=$(zgrep " died at " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de morts = $deadCount"
accountTotalCount=$(su -c "psql -U postgres -d minetest-auth --tuples-only -c \"SELECT COUNT(*) FROM auth\"" postgres | xargs)
echo "Nombre de comptes total = $accountTotalCount"
2023-07-09 17:37:52 +02:00
warningCount=$(zgrep "WARNING" /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
2023-07-16 08:56:31 +02:00
echo "Nombre de warning = $warningCount"
errorCount=$(zgrep "ERROR" /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre d'erreurs = $errorCount"
2023-07-09 17:37:52 +02:00
mcl2_databasesSize=$(su -c "psql -U postgres --tuples-only -c \"SELECT ROUND((CAST(SUM(pg_database_size(datname)) AS decimal) / 1024 / 1024)::numeric, 2) FROM pg_database WHERE datname LIKE 'minetest%mineclone2'\"" postgres | xargs)
echo "Taile des bases de données mineclone2 = $mcl2_databasesSize MB"
echo -e "\n"
}
# ============================================
echo
if [ "$#" = 1 ] && [ "$1" = "-h" ]; then
help
elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then
if [ "$(date +%m)" -gt 1 ]; then
precedingMonth="$((10#$(date +%m)-1))"
year="$(date +%Y)"
if [ $precedingMonth -lt 10 ]; then
month="${year}0$precedingMonth"
else
month="$year$precedingMonth"
fi
else
precedingMonth=12
year="$(($(date +%Y)-1))"
month="$year$precedingMonth"
fi
monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b)
echo -e "Rapport d'activité du service minetest.chapril.org -instance mineclone2- du mois $monthEnglish $year"
generateReport "$monthEnglish" "$month" "$year"
elif [ "$#" -eq 2 ]; then
if ! (let "$1") 2>/dev/null; then
echo -e "Le mois doit être numérique."
help
elif ([ "$1" -lt 1 ] || [ "$1" -gt 12 ]); then
echo -e "Numéro du mois non valable $1."
help
elif ! (let "$2") 2>/dev/null; then
echo -e "L'année doit être numérique."
help
elif [ "$2" -lt 2018 ] || [ "$2" -gt "$(date +%Y)" ]; then
echo -e "Année non valable $2."
help
elif [ "$2" -le 2017 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then
echo -e "Pas de données pour ce mois."
help
else
if [ "$1" -lt 10 ]; then
month="$2"0"$1"
else
month="$2""$1"
fi
monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b)
year="$2"
echo -e "Rapport d'activité du service minetest.chapril.org -instance mineclone2- du mois $monthEnglish $2"
generateReport "$monthEnglish" "$month" "$year"
fi
elif [ "$#" -eq 0 ]; then
month="$(date +%Y%m)"
monthEnglish=$(LANG=en_EN.UTF-8;date +%b)
year="$(date +%Y)"
echo -e "Rapport d'activité du service minetest.chapril.org -instance mineclone2- du mois $(date +%b) 20$(date +%y)"
generateReport "$monthEnglish" "$month" "$year"
else
echo -e "Bad parameter."
help
fi