#!/usr/bin/env bash 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")" stat --version 2>/dev/null | grep -q 'GNU coreutils' || { echo >&2 "Not gnu stat!"; exit 1; } logf_dbsize="log_dbsize.txt" [[ -f $logf_dbsize ]] && echo "Appending to '$logf_dbsize'" || echo "Logging to '$logf_dbsize'" while true; do now="$EPOCHSECONDS" dbsize=$(stat -c '%s' ../db.db) echo "$now $dbsize" >>"$logf_dbsize" if [[ -n $PLOTDIR ]]; then gnuplot <