2019-12-27 11:17:05 +01:00
|
|
|
#! /bin/bash
|
|
|
|
#
|
|
|
|
# Copyright (C) 2019 Laurent Poujoulat <lpoujoulat@april.org>
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# ============================================
|
|
|
|
# This scripts reads the nextcloud state, extract the main status variables
|
|
|
|
# and writes a plain text report on stdout
|
|
|
|
# ============================================
|
|
|
|
|
2020-03-31 10:26:00 +02:00
|
|
|
# Configuration data
|
2019-12-27 11:17:05 +01:00
|
|
|
CURL_CREDENTIAL="/etc/valise.chapril.org/curl_credential"
|
|
|
|
VALISE_STATS_DIR="/var/lib/valise.chapril.org"
|
|
|
|
VALISE_STATS_FILE="${VALISE_STATS_DIR}/stats"
|
2020-03-31 10:26:00 +02:00
|
|
|
VALISE_BASE_DIR="/var/www/valise.chapril.org"
|
|
|
|
VALISE_UPDATER_DIR="${VALISE_BASE_DIR}/data/updater-oc30zo96k0y3"
|
2019-12-27 11:17:05 +01:00
|
|
|
|
|
|
|
# Extract a json value by path (given as argument)
|
|
|
|
# The global JSON state is expected to be in NEXTCLOUD_STATE
|
|
|
|
# Only give the path part within the ocs.data section
|
|
|
|
getNcState()
|
|
|
|
{
|
|
|
|
echo ${NEXTCLOUD_STATE} | jq ".ocs.data.$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Read and store the current service state
|
|
|
|
NEXTCLOUD_STATE=`curl --silent --netrc-file ${CURL_CREDENTIAL} http://localhost/ocs/v2.php/apps/serverinfo/api/v1/info?format=json`
|
|
|
|
|
2019-12-27 15:09:16 +01:00
|
|
|
# Extraction of Nextcloud important values
|
2019-12-27 11:17:05 +01:00
|
|
|
NB_OF_USERS=$(getNcState "nextcloud.storage.num_users")
|
|
|
|
NB_OF_FILES=$(getNcState "nextcloud.storage.num_files")
|
2020-03-31 10:26:00 +02:00
|
|
|
NB_OF_UPDATER_FILES=$(find ${VALISE_UPDATER_DIR} -type f|wc -l)
|
|
|
|
NB_OF_USER_FILES=$(( (${NB_OF_FILES}) - (${NB_OF_UPDATER_FILES}) - 4 ))
|
2019-12-27 11:17:05 +01:00
|
|
|
NB_OF_SHARES=$(getNcState "nextcloud.shares.num_shares")
|
2020-03-31 11:46:57 +02:00
|
|
|
USED_DISK_BYTES=$(du -sb "${VALISE_BASE_DIR}/data"|cut -f 1)
|
|
|
|
USED_DISK_GB=$(( (${USED_DISK_BYTES}) / (1024*1024*1024) ))
|
|
|
|
USED_DISK_USER_BYTES=$(du -sb --exclude="${VALISE_UPDATER_DIR}" --exclude="${VALISE_BASE_DIR}/data/*.log" "${VALISE_BASE_DIR}/data"|cut -f 1)
|
|
|
|
USED_DISK_USER_GB=$(( (${USED_DISK_USER_BYTES}) / (1024*1024*1024) ))
|
2019-12-27 11:17:05 +01:00
|
|
|
FREE_DISK_GB=$(( $(getNcState "nextcloud.system.freespace") / (1024*1024*1024) ))
|
|
|
|
DATABASE_SIZE_MB=$(( $(getNcState "server.database.size") / (1024*1024) ))
|
|
|
|
|
2020-03-31 11:46:57 +02:00
|
|
|
|
2019-12-27 11:17:05 +01:00
|
|
|
# Get previous values
|
|
|
|
NB_OF_USERS_P=0
|
|
|
|
NB_OF_FILES_P=0
|
2020-03-31 10:26:00 +02:00
|
|
|
NB_OF_USER_FILES_P=0
|
2019-12-27 11:17:05 +01:00
|
|
|
NB_OF_SHARES_P=0
|
2020-03-31 11:46:57 +02:00
|
|
|
USED_DISK_GB_P=0
|
|
|
|
USED_DISK_USER_GB_P=0
|
2019-12-27 11:17:05 +01:00
|
|
|
FREE_DISK_GB_P=0
|
|
|
|
DATABASE_SIZE_MB_P=0
|
|
|
|
|
|
|
|
if [ -e ${VALISE_STATS_FILE} ]
|
|
|
|
then
|
|
|
|
source ${VALISE_STATS_FILE}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Save current values for the next run
|
|
|
|
mkdir -p ${VALISE_STATS_DIR}
|
|
|
|
echo "NB_OF_USERS_P="${NB_OF_USERS} >> ${VALISE_STATS_FILE}
|
|
|
|
echo "NB_OF_FILES_P="${NB_OF_FILES} >> ${VALISE_STATS_FILE}
|
2020-03-31 10:26:00 +02:00
|
|
|
echo "NB_OF_USER_FILES_P="${NB_OF_USER_FILES} >> ${VALISE_STATS_FILE}
|
2019-12-27 11:17:05 +01:00
|
|
|
echo "NB_OF_SHARES_P="${NB_OF_SHARES} >> ${VALISE_STATS_FILE}
|
2020-03-31 11:46:57 +02:00
|
|
|
echo "USED_DISK_GB_P="${USED_DISK_GB} >> ${VALISE_STATS_FILE}
|
|
|
|
echo "USED_DISK_USER_GB_P="${USED_DISK_USER_GB} >> ${VALISE_STATS_FILE}
|
2019-12-27 11:17:05 +01:00
|
|
|
echo "FREE_DISK_GB_P="${FREE_DISK_GB} >> ${VALISE_STATS_FILE}
|
|
|
|
echo "DATABASE_SIZE_MB_P="${DATABASE_SIZE_MB} >> ${VALISE_STATS_FILE}
|
|
|
|
|
2020-03-31 11:46:57 +02:00
|
|
|
|
2019-12-27 11:17:05 +01:00
|
|
|
# Generate report
|
|
|
|
echo "Rapport d'activité du service valise.chapril.org au "`date "+%-d %B %Y"`
|
|
|
|
echo
|
2019-12-27 15:09:16 +01:00
|
|
|
echo "================================================================="
|
2019-12-27 11:17:05 +01:00
|
|
|
echo
|
|
|
|
writeStatValue "Nombre d'utilisateurs" "" ${NB_OF_USERS} ${NB_OF_USERS_P}
|
2020-03-31 10:26:00 +02:00
|
|
|
writeStatValue "Nombre total de fichiers" "" ${NB_OF_FILES} ${NB_OF_FILES_P}
|
|
|
|
writeStatValue "Nombre de fichiers utilisateurs" "" ${NB_OF_USER_FILES} ${NB_OF_USER_FILES_P}
|
2019-12-27 11:17:05 +01:00
|
|
|
writeStatValue "Nombre de partages" "" ${NB_OF_SHARES} ${NB_OF_SHARES_P}
|
2020-03-31 11:46:57 +02:00
|
|
|
writeStatValue "Espace disque occupé total" "Go" ${USED_DISK_GB} ${USED_DISK_GB_P}
|
|
|
|
writeStatValue "Espace disque occupé par les utilisateurs" "Go" ${USED_DISK_USER_GB} ${USED_DISK_USER_GB_P}
|
2019-12-27 11:17:05 +01:00
|
|
|
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}
|
|
|
|
|
2019-12-27 15:09:16 +01:00
|
|
|
# Addition des infos HTTP
|
|
|
|
/srv/valise.chapril.org/tools/rapports_activites/rapport_activites_http.sh -p
|
2019-12-27 11:17:05 +01:00
|
|
|
|