diff options
Diffstat (limited to 'monitoring/monitoring.sh')
-rwxr-xr-x | monitoring/monitoring.sh | 56 |
1 files changed, 53 insertions, 3 deletions
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 <<EOF +set terminal png size 960,640 +set output '$PLOTDIR/dbsize.png' +set grid +plot '$logf_dbsize' w lp +EOF + fi + sleep "$SLEEPTIME" done |