Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
What I use to capture data and create simple graphs for my site, this runs every minute via cron.
#!/bin/sh
name=neidetcher_access
rrdfile="/var/local/${name}.rrd"
imageDir="/home/demian/code/demian0311.github.com/_site"
case "$1" in
create)
rrdtool create $rrdfile --step 60 \
"DS:${name}:GAUGE:120:0:1000000" \
"RRA:AVERAGE:0:1:60" \
"RRA:AVERAGE:0:60:24"
;;
update)
http_value=`/usr/sbin/logtail -f /var/log/nginx/neidetcher.access.log \
-o /var/log/nginx/.neidetcher.access.log.offset | wc -l`
https_value=`/usr/sbin/logtail -f /var/log/nginx/ssl_neidetcher.access.log \
-o /var/log/nginx/.ssl_neidetcher.access.log.offset| wc -l`
value=$(($http_value + $https_value))
rrdtool update $rrdfile N:${value}
;;
dump)
rrdtool dump $rrdfile
;;
graph)
rrdtool graph ./${name}_hour.png \
--start end-1h \
DEF:${name}=${rrdfile}:${name}:AVERAGE \
AREA:${name}#aa5555:${name}
mv -f ./${name}_hour.png ${imageDir}/${name}_hour.png
rrdtool graph ./${name}_day.png \
--start end-24h \
DEF:${name}=${rrdfile}:${name}:AVERAGE \
AREA:${name}#aa5555:${name}
mv -f ./${name}_day.png ${imageDir}/${name}_day.png
;;
*)
echo "usage: $0 {create|update|graph}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.