From 5694d60621969f2d531f5cdda3a19f1e3f958c07 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 30 Aug 2020 15:27:15 +0200 Subject: monitoring: Also plot --- monitoring/monitoring.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) (limited to 'monitoring/monitoring.sh') diff --git a/monitoring/monitoring.sh b/monitoring/monitoring.sh index b09489d..328c3f6 100755 --- a/monitoring/monitoring.sh +++ b/monitoring/monitoring.sh @@ -2,6 +2,49 @@ set -euo pipefail SLEEPTIME=60 +PLOTDIR="" + +function usage() { + echo >&2 "Usage: $0 [-s sleeptime] [-o plotdir]" + echo >&2 " -s sleeptime Time to sleep between polls; default $SLEEPTIME seconds" + echo >&2 " -o plotdir Output directory for plots; default none" +} + +ARGS=$(getopt -o 'hs:o:' -n "$0" -- "$@") +eval set -- "$ARGS" +unset ARGS + +while true; do + case "$1" in + -h) + usage + exit 0 + ;; + + -s) + SLEEPTIME="$2" + shift 2 + ;; + + -o) + PLOTDIR="$2" + shift 2 + ;; + + --) + shift + break + ;; + esac +done + +if [[ $# -gt 0 ]]; then + usage + exit 1 +fi + +[[ -n $PLOTDIR ]] && PLOTDIR=$(realpath "$PLOTDIR") +[[ ! -d $PLOTDIR ]] && { echo >&2 "'$PLOTDIR' is not a directory"; exit 1; } cd "$(dirname "$0")" @@ -12,12 +55,19 @@ stat --version 2>/dev/null | grep -q 'GNU coreutils' || { logf_dbsize="log_dbsize.txt" [[ -f $logf_dbsize ]] && echo "Appending to '$logf_dbsize'" || echo "Logging to '$logf_dbsize'" -echo "Monitoring: logging every $SLEEPTIME seconds" - while true; do now="$EPOCHSECONDS" - dbsize="$(stat -c '%s' ../db.db)" + dbsize=$(stat -c '%s' ../db.db) echo "$now $dbsize" >>"$logf_dbsize" + if [[ -n $PLOTDIR ]]; then + gnuplot <