Assuming we take a reading once every 5 minutes from cron, we want to store every reading for 1 day, the half-hour average for a week and the hourly average for 2 years.
rdtool create foo.rrd --step 300 DS:NFSOPS:COUNTER:3600:U:U \ RRA:AVERAGE:0.8:1:300 \ RRA:AVERAGE:0.8:6:2016 \ RRA:AVERAGE:0.8:12:17520
For 1 datasource, this creates a file 156k in size, and stores 2 years worth of data. To add multiple datasources, say CIFS Ops, add another DS:CIFSOPS:COUNTER:3600:U:U after the first DS and before the averages.
All the examples I’ve seen for RRDTool seem to imply you want to create the RRDdatabase by hand for each object you want to graph. Forget that! I’ve put everything into a bash script, and both scripts below are run every 5 minutes from cron.
#!/bin/bash
cd /usr/local/systems/rrdtool
rrdtool="/usr/local/systems/rrdtool/bin/rrdtool"
file="/usr/local/systems/rrdtool/netapp.rrd"
if [ ! -f "$file" ] ; then
$rrdtool create $file --step 300 DS:NFSOPS:COUNTER:3600:U:U \
RRA:AVERAGE:0.8:1:300 \
RRA:AVERAGE:0.8:6:2016 \
RRA:AVERAGE:0.8:12:17520
fi
# Connect to machine and read the output
NFSOPS=`/usr/bin/snmpget bailey public .1.3.6.1.4.1.789.1.2.2.1.0 | awk '{print $NF}'`
$rrdtool update $file N:$NFSOPS
Draw the graphs
#!/bin/bash rrdtool="/usr/local/systems/rrdtool/bin/rrdtool" filename="netapp.rrd" graphname="bailey-nfs" DS="NFSOPS" title="Bailey NFS Ops" key="NFS Ops" scale="Ops" $rrdtool graph -u 40 $graphname-day.png -v "$scale" -L 5 --start -86400 \ -t "$title (past 24 hours)" \ DEF:$DS=$filename:$DS:AVERAGE LINE2:$DS#FF0000:"$key" \ "COMMENT:\n" \ "GPRINT:$DS:MAX: Max\: %.0lf" \ "GPRINT:$DS:MIN:Min\: %.0lf" \ "GPRINT:$DS:AVERAGE:Avg\: %.0lf" \ "GPRINT:$DS:LAST:Cur\: %.0lf" \ "COMMENT:\n" > /dev/null $rrdtool graph -u 40 $graphname-week.png -v "$scale" -L 5 --start -604800 \ -t "$title (past 7 days)" \ DEF:$DS=$filename:$DS:AVERAGE LINE2:$DS#FF0000:"$key" \ "COMMENT:\n" \ "GPRINT:$DS:MAX: Max\: %.0lf" \ "GPRINT:$DS:MIN:Min\: %.0lf" \ "GPRINT:$DS:AVERAGE:Avg\: %.0lf" \ "GPRINT:$DS:LAST:Cur\: %.0lf" \ "COMMENT:\n" > /dev/null $rrdtool graph -u 40 $graphname-month.png -v "$scale" -L 5 --start -2592000 \ -t "$title (past 30 days)" \ DEF:$DS=$filename:$DS:AVERAGE LINE2:$DS#FF0000:"$key" \ "COMMENT:\n" \ "GPRINT:$DS:MAX: Max\: %.0lf" \ "GPRINT:$DS:MIN:Min\: %.0lf" \ "GPRINT:$DS:AVERAGE:Avg\: %.0lf" \ "GPRINT:$DS:LAST:Cur\: %.0lf" \ "COMMENT:\n" > /dev/null $rrdtool graph -u 40 $graphname-annual.png -v "$scale" -L 5 --start -31536000 \ -t "$title (past 365 days)" \ DEF:$DS=$filename:$DS:AVERAGE LINE2:$DS#FF0000:"$key" \ "COMMENT:\n" \ "GPRINT:$DS:MAX: Max\: %.0lf" \ "GPRINT:$DS:MIN:Min\: %.0lf" \ "GPRINT:$DS:AVERAGE:Avg\: %.0lf" \ "GPRINT:$DS:LAST:Cur\: %.0lf" \ "COMMENT:\n" > /dev/null
Our UPS has 3 outputs, which we can monitor as a percentage, with SNMP. We are also interested in the estmated run time remaining. Using the MIB file that comes on the CD with the UPS, we have the basis for SNMP readings (see my SNMP notes for more information).
#!/bin/bash
rrdtool="/usr/local/systems/rrdtool/bin/rrdtool"
file="/usr/local/systems/rrdtool/ups/ups.rrd"
if [ ! -f "$file" ] ; then
$rrdtool create $file \
DS:Load1:GAUGE:600:U:U \
DS:Load2:GAUGE:600:U:U \
DS:Load3:GAUGE:600:U:U \
DS:TimeLeft:GAUGE:500:U:U \
RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797
fi
snmpget="/usr/bin/snmpget ups public -m /usr/share/snmp/mibs/stdupsv1.mib"
Load1=`$snmpget UPS-MIB::upsOutputPercentLoad.1 | awk '{print $NF}'`
Load2=`$snmpget UPS-MIB::upsOutputPercentLoad.2 | awk '{print $NF}'`
Load3=`$snmpget UPS-MIB::upsOutputPercentLoad.3 | awk '{print $NF}'`
TimeLeft=`$snmpget UPS-MIB::upsEstimatedMinutesRemaining | awk '{print $NF}'`
$rrdtool update $file N:$Load1:$Load2:$Load3:$TimeLeft
#!/bin/bash
rrdtool="/usr/local/systems/rrdtool/bin/rrdtool"
workdir="/usr/local/systems/rrdtool/ups"
wwwimagedir="/usr/local/systems/mrtg-www/ups/"
filename="/usr/local/systems/rrdtool/ups/ups.rrd"
cd $workdir
dograph() {
name=$1
seconds=$2
text=$3
source=$4
title=$5
scale=$6
$rrdtool graph -u 100 -l 0 $name.png -v "$scale" \
-L 8 --start -$seconds -t "$title" \
DEF:$source=$filename:$source:AVERAGE \
AREA:$source#FF0000:"$title " \
"GPRINT:$source:MAX:Max\: %.0lf$scale" \
"GPRINT:$source:MIN:Min\: %.0lf$scale" \
"GPRINT:$source:AVERAGE:Avg\: %.0lf$scale" \
"GPRINT:$source:LAST:Cur\: %.0lf$scale" \
"COMMENT:\n" \
> /dev/null
}
dograph ups-load1-day 86400 "past 24 hours" Load1 "Line 1 Load" "%%"
dograph ups-load2-day 86400 "past 24 hours" Load2 "Line 2 Load" "%%"
dograph ups-load3-day 86400 "past 24 hours" Load3 "Line 3 Load" "%%"
dograph ups-runtime-day 86400 "past 24 hours" TimeLeft "Runtime Remaining" " Mins"
# Move the images from the $workdir to $wwwimagedir
mv $workdir/*.png $wwwimagedir