blob: 91b2e4abafbce2939c81cb1603c59620580b0096 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/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 <<EOF
set terminal png size 960,640
set output '$PLOTDIR/dbsize.png'
set grid
plot '$logf_dbsize' u (\$1/3600/24):2 w lp
EOF
fi
sleep "$SLEEPTIME"
done
|