From 96e30089c1e63ce9214c3c2b24f69d04bd102f2c Mon Sep 17 00:00:00 2001 From: Laurent Poujoulat Date: Fri, 27 Dec 2019 15:09:16 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20statistiques=20HTTP=20au=20rappor?= =?UTF-8?q?t=20d'activit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rapports_activites/rapport_activites.sh | 7 +- rapports_activites/rapport_activites_http.sh | 127 +++++++++++++++++++ 2 files changed, 131 insertions(+), 3 deletions(-) create mode 100755 rapports_activites/rapport_activites_http.sh diff --git a/rapports_activites/rapport_activites.sh b/rapports_activites/rapport_activites.sh index 43af452..8d434e1 100755 --- a/rapports_activites/rapport_activites.sh +++ b/rapports_activites/rapport_activites.sh @@ -63,7 +63,7 @@ writeStatValue() # If something fails, NEXTCLOUD_STATE=`curl --silent --netrc-file ${CURL_CREDENTIAL} http://localhost/ocs/v2.php/apps/serverinfo/api/v1/info?format=json` -# Extraction of important values +# Extraction of Nextcloud important values NB_OF_USERS=$(getNcState "nextcloud.storage.num_users") NB_OF_FILES=$(getNcState "nextcloud.storage.num_files") NB_OF_SHARES=$(getNcState "nextcloud.shares.num_shares") @@ -93,7 +93,7 @@ echo "DATABASE_SIZE_MB_P="${DATABASE_SIZE_MB} >> ${VALISE_STATS_FILE} # Generate report echo "Rapport d'activité du service valise.chapril.org au "`date "+%-d %B %Y"` echo -echo "=======================================================================" +echo "=================================================================" echo writeStatValue "Nombre d'utilisateurs" "" ${NB_OF_USERS} ${NB_OF_USERS_P} writeStatValue "Nombre de fichiers" "" ${NB_OF_FILES} ${NB_OF_FILES_P} @@ -101,5 +101,6 @@ writeStatValue "Nombre de partages" "" ${NB_OF_SHARES} ${NB_OF_SHARES_P} writeStatValue "Espace disque disponible" "Go" ${FREE_DISK_GB} ${FREE_DISK_GB_P} writeStatValue "Espace occupé par la base de données" "Mo" ${DATABASE_SIZE_MB} ${DATABASE_SIZE_MB_P} - +# Addition des infos HTTP +/srv/valise.chapril.org/tools/rapports_activites/rapport_activites_http.sh -p diff --git a/rapports_activites/rapport_activites_http.sh b/rapports_activites/rapport_activites_http.sh new file mode 100755 index 0000000..bf8ca18 --- /dev/null +++ b/rapports_activites/rapport_activites_http.sh @@ -0,0 +1,127 @@ +#!/bin/bash +# +# Copyright (C) 2018,2019 Didier Clermonté +# Copyright (C) 2018,2019 Christian Pierre Momon +# Copyright (C) 2019 Laurent Poujoulat [pour la valise] +# +# This file is part of valise.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 . +# +# ============================================ +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 + httpRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-access.log*|grep -c "$year") + echo "Nombre total de requêtes http = $httpRequestCount" + + trueHttpRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -c -v check_http) + echo "Nombre de vraies requêtes http = $trueHttpRequestCount" + + botRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) + echo "Nombre de requêtes bot = $botRequestCount" + + errorRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-error.log*|grep -c "$year") + echo "Nombre de requêtes http en erreur = $errorRequestCount" + + ipv4Count=$(zgrep -h "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\} '|cut -d' ' -f1|sort|uniq |wc -l) + echo "Nombre d'ipv4 ayant visité le service = $ipv4Count" + + ipv6Count=$(zgrep -h "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9a-f]\{0,4\}:\)\{2,7\}\([0-9a-f]\{0,4\}\)\{1\} '|cut -d' ' -f1|sort|uniq |wc -l) + echo "Nombre d'ipv6 ayant visité le service = $ipv6Count" + + echo "Nombre total d'ip ayant visité le service = $((ipv4Count+ipv6Count))" + + ipv4UserCount=$(zgrep -h "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\} '|grep "\(PROPFIND /remote\.php/\|GET /apps/files/\)"|grep -v "HTTP/1.0\" 404"|grep -v "HEAD"|cut -d' ' -f1|sort|uniq|wc -l ) + echo "Nombre d'ipv4 utilisatrices = $ipv4UserCount" + + ipv6UserCount=$(zgrep -h "$monthEnglish" /var/log/apache2/valise.chapril.org/valise.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9a-f]\{0,4\}:\)\{2,7\}\([0-9a-f]\{0,4\}\)\{1\} '|grep -v "::1 "|grep "\(PROPFIND /remote\.php/\|GET /apps/files/\)"|grep -v "HTTP/1.0\" 404"|grep -v "HEAD"|cut -d' ' -f1|sort|uniq|wc -l ) + echo "Nombre d'ipv6 utilisatrices = $ipv6UserCount" + + echo "Nombre total d'ip ayant utilisées le service = $((ipv4UserCount+ipv6UserCount))" + + 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))" + fi + monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b) + echo + 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 valise.chapril.org 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 valise.chapril.org du mois $(date +%b) 20$(date +%y)" + generateReport "$monthEnglish" "$month" "$year" +else + echo -e "Bad parameter." + help +fi