diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-08-30 15:27:15 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-08-30 15:27:15 +0200 |
commit | 5694d60621969f2d531f5cdda3a19f1e3f958c07 (patch) | |
tree | 1ea4d0dfa47780a0b0ed6f49773a5cefc8ca4cbe /monitoring | |
parent | 860e402d6372a0ede1cf97ff5af358fc339b2b3a (diff) |
monitoring: Also plot
Diffstat (limited to 'monitoring')
-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 |