From c4e5501b4746fb12ebc7b40d94b7ba290a018752 Mon Sep 17 00:00:00 2001 From: Laurent Poujoulat Date: Mon, 27 Apr 2020 16:02:20 +0200 Subject: [PATCH] Implemented first indicators for the mumble activity report: users and connections --- rapports_activites/rapport_activites.sh | 88 +++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 rapports_activites/rapport_activites.sh diff --git a/rapports_activites/rapport_activites.sh b/rapports_activites/rapport_activites.sh new file mode 100755 index 0000000..0d75d69 --- /dev/null +++ b/rapports_activites/rapport_activites.sh @@ -0,0 +1,88 @@ +#! /bin/bash +# +# Copyright (C) 2020 Laurent Poujoulat +# +# This file is part of mumble.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 . +# + +# ============================================ +# This scripts reads the nextcloud state, extract the main status variables +# and writes a plain text report on stdout +# ============================================ + +# Configuration data +MUMBLE_STATS_DIR="/var/lib/mumble.chapril.org" +MUMBLE_STATS_FILE="${VALISE_STATS_DIR}/stats" + +# Format statistic value for the report +writeStatValue() +{ + local LABEL=$1 + local UNIT=$2 + local CUR_VALUE=$3 + local PREV_VALUE=$4 + local VARIATION=$(( ${CUR_VALUE}-${PREV_VALUE} )) + + if [ ${VARIATION} -gt 0 ] + then + VARIATION="+"${VARIATION} + fi + + if [ "${UNIT}" == "" ] + then + echo ${LABEL}": "${CUR_VALUE}" ("${VARIATION}")" + else + echo ${LABEL}": "${CUR_VALUE}" "${UNIT}" ("${VARIATION}")" + fi +} + + +# Extraction mumble important values +NB_OF_USERS=0 +NB_OF_CONNECTIONS=0 + +# Work out iso date match for prev month +PREV_MONTH_MATCH=$(date +%Y-%m -d "1 month ago") +NB_OF_CONNECTIONS=$(grep -hE "${PREV_MONTH_MATCH}.*New connection" /var/log/mumble-server/*.log.*|wc -l) +NB_OF_USERS=$(grep -hE "${PREV_MONTH_MATCH}.*Authenticated" /var/log/mumble-server/*.log.*|grep -hEo "<[0-9]+\:.*\(-1\)"|grep -hEo "\:.*"|sort|uniq|wc -l) + + +# Get previous values +NB_OF_USERS_P=0 +NB_OF_CONNECTIONS_P=0 + +if [ -e ${MUMBLE_STATS_FILE} ] +then + source ${MUMBLE_STATS_FILE} +fi + +# Save current values for the next run +mkdir -p ${MUMBLE_STATS_DIR} +echo "NB_OF_USERS_P="${NB_OF_USERS} >> ${MUMBLE_STATS_FILE} +echo "NB_OF_CONNECTIONS_P="${NB_OF_CONNECTIONS} >> ${MUMBLE_STATS_FILE} + + +# Generate report +echo "Rapport d'activité du service mumble.chapril.org au "`date "+%-d %B %Y"` +echo +echo "=================================================================" +echo +writeStatValue "Nombre d'utilisateurs" "" ${NB_OF_USERS} ${NB_OF_USERS_P} +writeStatValue "Nombre de connexions" "" ${NB_OF_CONNECTIONS} ${NB_OF_CONNECTIONS_P} + +# Addition des infos HTTP +# /srv/mumble.chapril.org/tools/rapports_activites/rapport_activites_http.sh -p +