Home > HowTo > Learning RRD

Learning RRD

January 22nd, 2009 Leave a comment Go to comments

“RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. Use it to write your custom monitoring shell scripts or create whole applications using its Perl, Python, Ruby, TCL or PHP bindings”
RRD = Round Robin Database Tool, this means the size of the DB does not keep growing!
I just rewrote a simplified the tutuorial, and wrote as I was learning how to use RRD. THe idea is to learn how to create custom graphs in Nagios and Centreon.

Creating a simple DB strucutre
# rrdtool create test.rrd –start 920804400 DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24 RRA:AVERAGE:0.5:6:10

The start Time is: 7th of March, 1999 (this date translates to 920’804’400 seconds as explained below). Our database holds one data source (DS) named “speed” that represents a counter. This counter is read every five minutes (this is the default therefore you don’t have to put –step=300). In the same database two round robin archives (RRAs) are kept, one averages the data every time it is read (e.g., there’s nothing to average) and keeps 24 samples (24 times 5 minutes is 2 hours). The other averages 6 values (half hour) and contains 10 such averages (e.g. 5 hours).

We now enter some data:
# rrdtool update test.rrd 920804700:12345 920805000:12357 920805300:12363
# rrdtool update test.rrd 920805600:12363 920805900:12363 920806200:12373
# rrdtool update test.rrd 920806500:12383 920806800:12393 920807100:12399
# rrdtool update test.rrd 920807400:12405 920807700:12411 920808000:12415
# rrdtool update test.rrd 920808300:12420 920808600:12422 920808900:12423

In this example we are enetring only values per line, but this can be even more, its basicly the TIMESTAMP:VALUE

If we do a test fetch
# rrdtool fetch test.rrd AVERAGE –start 920804400 –end 920809200 speed
Should output some TIMESTAMP:VALUE like 920805000: 4.0000000000e-02 The value is in some mathemtical format whiel “NaN” stands for “Not A Number”

# rrdtool graph speed.png –start 920804400 –end 920808000 DEF:myspeed=test.rrd:speed:AVERAGE LINE2:myspeed#FF0000

With the Labels
# rrdtool graph speed2.png –start 920804400 –end 920808000 –vertical-label m/s DEF:myspeed=test.rrd:speed:AVERAGE CDEF:realspeed=myspeed,1000, LINE2:realspeed#FF0000

With KM/H
# rrdtool graph speed3.png –start 920804400 –end 920808000 –vertical-label km/h DEF:myspeed=test.rrd:speed:AVERAGE “CDEF:kmh=myspeed,3600,*” CDEF:fast=kmh,100,GT,kmh,0,IF CDEF:good=kmh,100,GT,0,kmh,IF HRULE:100#0000FF:”Maximum allowed” AREA:good#00FF00:”Good speed” AREA:fast#FF0000:”Too fast”

The calculations are more complex now. For speed measurements within the speed limit they are:
Check if kmh is greater than 100 ( kmh,100 ) GT
If so, return 0, else kmh ((( kmh,100 ) GT ), 0, kmh) IF

For values above the speed limit:
Check if kmh is greater than 100 ( kmh,100 ) GT
If so, return kmh, else return 0 ((( kmh,100) GT ), kmh, 0) IF

More Magic

# rrdtool graph speed4.png –start 920804400 –end 920808000 –vertical-label km/h DEF:myspeed=test.rrd:speed:AVERAGE “CDEF:kmh=myspeed,3600,*” CDEF:fast=kmh,100,GT,100,0,IF CDEF:over=kmh,100,GT,kmh,100,-,0,IF CDEF:good=kmh,100,GT,0,kmh,IF HRULE:100#0000FF:”Maximum allowed” AREA:good#00FF00:”Good speed” AREA:fast#550000:”Too fast” STACK:over#FF0000:”Over speed”

this tuttorial credit goes to http://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html

Categories: HowTo Tags: , , , ,

VAMOVE *

*