From 99da7b05f78fa584b7c8009b345fc78256504a9d Mon Sep 17 00:00:00 2001 From: Leander Hutton Date: Tue, 10 Jun 2014 14:35:54 -0400 Subject: [PATCH] Initial commit. --- README | 19 +++++++++ rrd_config | 6 +++ rrd_init_databases.sh | 64 +++++++++++++++++++++++++++++ update_graphs.sh | 95 +++++++++++++++++++++++++++++++++++++++++++ update_rrds.sh | 45 ++++++++++++++++++++ 5 files changed, 229 insertions(+) create mode 100644 README create mode 100755 rrd_config create mode 100755 rrd_init_databases.sh create mode 100755 update_graphs.sh create mode 100755 update_rrds.sh diff --git a/README b/README new file mode 100644 index 0000000..d6691d2 --- /dev/null +++ b/README @@ -0,0 +1,19 @@ +RRD Scripts +v0.1 + +leander@one-button.org +www.one-button.org + +Graphs load average, disk usage, and network throughput. + +Something simple I put together for some basic graphs, not a Cacti replacement. Requires RRD and presumably some web server to display the graphs. + +Make sure you adjust the settings in the rrd_config file before you install. + +Run the rrd_init_databases.sh to intialize the databases, then run ./update_rrds.sh &. You may want to put that in rc.local or some equivalent so it runs on boot. + +To have the graphs generated automatically add something like + +*/5 * * * * /path/to/rrd_scripts/update_graphs.sh > /dev/null 2>&1 + +to your crontab. diff --git a/rrd_config b/rrd_config new file mode 100755 index 0000000..cbd9ba9 --- /dev/null +++ b/rrd_config @@ -0,0 +1,6 @@ +INTERFACES=( eth0 eth1 ) +DISKS=( sda sdb md0 ) +RRDDIR="/usr/local/rrd/" +GRAPHDIR="/usr/local/graphs/" +RRDTOOL="/usr/bin/rrdtool" +IOSTAT="/usr/bin/iostat" diff --git a/rrd_init_databases.sh b/rrd_init_databases.sh new file mode 100755 index 0000000..60d3ad0 --- /dev/null +++ b/rrd_init_databases.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Simple RRD setup +# Netowrk traffic in bytes/sec +# Disk reads/writes in bytes/sec +# Load average as reported by /proc/loadavg +# Needs: sysstat iostat + +CONFIGDIR=$(pwd) +sed "3i . ${CONFIGDIR}/rrd_config" update_graphs.sh > update_graphs.sh + +. ${CONFIGDIR}/rrd_config + +if [ ! -d "$RRDDIR" ]; then + mkdir -p $RRDDIR +fi + +cd $RRDDIR + +# Create RRDs for network interfaces +for i in "${INTERFACES[@]}" +do + if [ ! -f ${i}_day.rrd ]; then + $RRDTOOL create ${i}_day.rrd \ + --step 15 \ + DS:RXBytes:DERIVE:240:0:1000000000000000 \ + DS:TXBytes:DERIVE:240:0:1000000000000000 \ + RRA:AVERAGE:0.5:1:576 \ + RRA:AVERAGE:0.5:6:672 \ + RRA:AVERAGE:0.5:24:732 \ + RRA:AVERAGE:0.5:144:1460 + fi +done + +# Create RRDs for disks +for i in "${DISKS[@]}" +do + if [ ! -f {i}.rrd ]; then + $RRDTOOL create ${i}.rrd \ + --step 15 \ + DS:reads:DERIVE:30:0:1000000000000000 \ + DS:writes:DERIVE:30:0:1000000000000000 \ + RRA:AVERAGE:0.5:1:576 \ + RRA:AVERAGE:0.5:6:672 \ + RRA:AVERAGE:0.5:24:732 \ + RRA:AVERAGE:0.5:144:1460 + fi +done + +# Create load average RRD +if [ ! -f loadavg.rrd ]; then + $RRDTOOL create loadavg.rrd \ + --step 15 \ + DS:one:GAUGE:30:0:100 \ + DS:five:GAUGE:30:0:100 \ + DS:fifteen:GAUGE:30:0:100 \ + RRA:AVERAGE:0.5:1:576 \ + RRA:AVERAGE:0.5:6:672 \ + RRA:AVERAGE:0.5:24:732 \ + RRA:AVERAGE:0.5:144:1460 +fi + + + diff --git a/update_graphs.sh b/update_graphs.sh new file mode 100755 index 0000000..b8251cb --- /dev/null +++ b/update_graphs.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +. /root/rrd_scripts/rrd_config + +if [ ! -d $GRAPHDIR ]; then + mkdir -p $GRAPHDIR +fi + +cd $RRDDIR + +for i in ${INTERFACES[@]} +do + $RRDTOOL graph $GRAPHDIR${i}_day.png \ + -h 120 -w 550 -a PNG \ + --start end-8h --end now \ + --font DEFAULT:7: \ + --title "$i Network Throughput" \ + --watermark "`date`" \ + --vertical-label "bytes/sec" \ + --logarithmic \ + --units=si \ + --x-grid MINUTE:10:HOUR:1:MINUTE:120:0:%R \ + --alt-y-grid --rigid \ + DEF:RXBytes=${i}_day.rrd:RXBytes:AVERAGE \ + DEF:TXBytes=${i}_day.rrd:TXBytes:AVERAGE \ + LINE2:RXBytes#3ADF00:RX \ + GPRINT:RXBytes:LAST:"Cur\: %5.2lf %s" \ + GPRINT:RXBytes:AVERAGE:"Avg\: %5.2lf %S" \ + GPRINT:RXBytes:MAX:"Max\: %5.2lf %S" \ + GPRINT:RXBytes:MIN:"Min\: %5.2lf %SBps\n" \ + LINE2:TXBytes#045FB4:TX \ + GPRINT:TXBytes:LAST:"Cur\: %5.1lf %s" \ + GPRINT:TXBytes:AVERAGE:"Avg\: %5.1lf %S" \ + GPRINT:TXBytes:MAX:"Max\: %5.1lf %S" \ + GPRINT:TXBytes:MIN:"Min\: %5.1lf %SBps\n" \ + HRULE:0#000000 +done + + +for i in ${DISKS[@]} +do + $RRDTOOL graph $GRAPHDIR${i}.png \ + -h 120 -w 550 -a PNG \ + --start end-8h --end now \ + --font DEFAULT:7: \ + --title "${i} Data Read/Written" \ + --watermark "`date`" \ + --vertical-label "bytes/sec" \ + --logarithmic \ + --units=si \ + --x-grid MINUTE:10:HOUR:1:MINUTE:120:0:%R \ + --alt-y-grid --rigid \ + DEF:reads=${i}.rrd:reads:AVERAGE \ + DEF:writes=${i}.rrd:writes:AVERAGE \ + LINE2:reads#3ADF00:Read \ + GPRINT:reads:LAST:"Cur\: %5.2lf %s" \ + GPRINT:reads:AVERAGE:"Avg\: %5.2lf %S" \ + GPRINT:reads:MAX:"Max\: %5.2lf %S" \ + GPRINT:reads:MIN:"Min\: %5.2lf %SBps\n" \ + LINE2:writes#045FB4:Written \ + GPRINT:writes:LAST:"Cur\: %5.1lf %s" \ + GPRINT:writes:AVERAGE:"Avg\: %5.1lf %S" \ + GPRINT:writes:MAX:"Max\: %5.1lf %S" \ + GPRINT:writes:MIN:"Min\: %5.1lf %SBps\n" \ + HRULE:0#000000 +done + +$RRDTOOL graph $GRAPHDIR/loadavg.png \ +-h 120 -w 550 -a PNG \ +--start end-8h --end now \ +--font DEFAULT:7: \ +--title "Load Average" \ +--watermark "`uptime`" \ +--vertical-label "Load Average" \ +--x-grid MINUTE:10:HOUR:1:MINUTE:120:0:%R \ +--upper-limit 2.00 \ +--lower-limit 0.00 \ +DEF:one=loadavg.rrd:one:AVERAGE \ +DEF:five=loadavg.rrd:five:AVERAGE \ +DEF:fifteen=loadavg.rrd:fifteen:AVERAGE \ +LINE:fifteen#FF0000:"1 Min\:" \ +GPRINT:fifteen:LAST:"Cur\: %5.2lf" \ +GPRINT:fifteen:AVERAGE:"Avg\: %5.2lf" \ +GPRINT:fifteen:MIN:"Min\: %5.2lf" \ +GPRINT:fifteen:MAX:"Max\: %5.2lf\n" \ +LINE:five#0000FF:"5 Min\:" \ +GPRINT:five:LAST:"Cur\: %5.2lf" \ +GPRINT:five:AVERAGE:"Avg\: %5.2lf" \ +GPRINT:five:MIN:"Min\: %5.2lf" \ +GPRINT:five:MAX:"Max\: %5.2lf\n" \ +AREA:one#00FF0080:"15 Min\:" \ +GPRINT:one:LAST:"Cur\: %5.2lf" \ +GPRINT:one:AVERAGE:"Avg\: %5.2lf" \ +GPRINT:one:MIN:"Min\: %5.2lf" \ +GPRINT:one:MAX:"Max\: %5.2lf\n" \ diff --git a/update_rrds.sh b/update_rrds.sh new file mode 100755 index 0000000..69f9130 --- /dev/null +++ b/update_rrds.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +CONFIGPATH=$(pwd) + +while [ true ] + do + +. ${CONFIGPATH}/rrd_config + +cd $RRDDIR + +for i in "${INTERFACES[@]}" +do + # By default I use ifconfig, if you prefer + # iproute2 simply comment out the next two lines + # and uncomment the other ones. + RX=$(/sbin/ifconfig $i | grep bytes | cut -f2 -d":" | cut -f1 -d " ") + TX=$(/sbin/ifconfig $i | grep bytes | cut -f3 -d":" | cut -f1 -d " ") + + #RX=$(/sbin/ip -o -s link show eth0 | cut -f40 -d" ") + #TX=$(/sbin/ip -o -s link show eth0 | cut -f84 -d" ") + + $RRDTOOL update ${i}_day.rrd --template RXBytes:TXBytes N:${RX}:${TX} +done + +for i in "${DISKS[@]}" +do + READS=$(${IOSTAT} -d $i | grep $i | awk {'print $5'}) + WRITES=$(${IOSTAT} -d $i | grep $i | awk {'print $6'}) + + READSB=$((${READS}*1000)) + WRITESB=$((${WRITES}*1000)) + + $RRDTOOL update ${i}.rrd --template reads:writes N:${READSB}:${WRITESB} +done + +ONEMIN=$(cat /proc/loadavg | awk {'print $1'}) +FIVEMIN=$(cat /proc/loadavg | awk {'print $2'}) +FIFTEENMIN=$(cat /proc/loadavg | awk {'print $3'}) + +$RRDTOOL update loadavg.rrd --template one:five:fifteen N:${ONEMIN}:${FIVEMIN}:${FIFTEENMIN} + +sleep 7 + +done