-
-
Save jackjm/164293e4fbc24a0b45d9 to your computer and use it in GitHub Desktop.
What I use to capture data and create simple graphs for my site, this runs every minute via cron.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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