Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Created September 9, 2014 21:44
Show Gist options
  • Save tolleiv/e443f944833c6e05a327 to your computer and use it in GitHub Desktop.
Save tolleiv/e443f944833c6e05a327 to your computer and use it in GitHub Desktop.
RRDtool example code
#!/bin/bash
let time=1407882500
let now=$(( time+300 ))
rm datafile.rrd
rrdtool create datafile.rrd --start $time --step 60 \
DS:hdduse:GAUGE:100:0:100 \
RRA:AVERAGE:0.5:1:1440 \
RRA:AVERAGE:0.5:60:720 \
RRA:MAX:0.5:1:1440 \
RRA:MAX:0.5:60:720 \
RRA:MIN:0.5:1:1440 \
RRA:MIN:0.5:60:720
rrdtool update datafile.rrd $(( $time+60 )):10
rrdtool update datafile.rrd $(( $time+120 )):30
rrdtool update datafile.rrd $(( $time+180 )):35
rrdtool update datafile.rrd $(( $time+240 )):50
rrdtool update datafile.rrd $(( $time+300 )):55
rrdtool graph graph.png \
--start $time --end $(( $time+900 )) \
--lower-limit 0 --upper-limit 100 --rigid \
DEF:pkt=datafile.rrd:hdduse:AVERAGE \
VDEF:slope=pkt,LSLSLOPE \
VDEF:cons=pkt,LSLINT \
CDEF:lsl2=pkt,POP,slope,COUNT,*,cons,+ \
CDEF:pred=lsl2,80,100,LIMIT \
VDEF:minpred=pred,FIRST \
VDEF:maxpred=pred,LAST \
LINE1:lsl2#991111:"Least Sqr Pred.\n":dashes=8 \
LINE2:pkt#0044aa:"Percentage"\
LINE3:80 \
AREA:10#FF000022::STACK \
AREA:10#FF000044::STACK \
GPRINT:minpred:"reaching 80 on \: %c\n":strftime \
GPRINT:maxpred:"reaching 100 on \: %c\n":strftime
rrdtool graph /dev/null -f '' \
--start $time --end $(( $time+900 )) \
--lower-limit 0 --upper-limit 100 --rigid \
DEF:pkt=datafile.rrd:hdduse:AVERAGE \
VDEF:slope=pkt,LSLSLOPE \
VDEF:cons=pkt,LSLINT \
CDEF:lsl2=pkt,POP,slope,COUNT,*,cons,+ \
CDEF:pred=lsl2,80,100,LIMIT \
VDEF:minpred=pred,FIRST \
VDEF:maxpred=pred,LAST \
PRINT:minpred:"reaching 80 on \: %c":strftime \
PRINT:maxpred:"reaching 100 on \: %c":strftime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment