RRDTool

From vWiki
Jump to: navigation, search

http://oss.oetiker.ch/rrdtool/index.en.html - RRDTool homepage

Getting Started

Installation

This section assumes you want to install both RRDTool (which is responsible for managing and presenting data) and MRTG (which is responsible for data collection). Strictly speaking MRTG isn't needed, but when you're first getting started it makes things much easier.

To install on Ubuntu...

  1. Install MRTG
    • apt-get mrtg
    • Answer yes to making mrtg.conf accessible by root only
  2. Install RRDTool
    • apt-get rrdtool

If you're installing on Windows see here - http://oss.oetiker.ch/mrtg/doc/mrtg-nt-guide.en.html. The rrdtool exe's for Windows can be found in the latest Win32-Perl package from http://oss.oetiker.ch/rrdtool/pub/?M=D (currently rrdtool-1.2.30-win32-perl510.zip, as of Nov 2012)

Config Maker (cfgmaker)

cfgmaker --global "Interval: 1" --global "LogFormat: rrdtool" --global "Options[_]: bits,growright" --output /home/mrtg/cfg/mrtg.cfg public@router

Create a Database

The following example creates a RRD database to hold an ESX's aggregated (average of all cores) CPU data with;

  • Raw data held for 12 hrs (realtime)
  • 5 min average (with max and min values) for 24 hrs (daily)
  • 20 min average (with max and min values) for 7 days (weekly)
  • 60 min average (with max and min values) for 31 days (monthly)
  • 1 day average (with max and min values) for 365 days (yearly)

In order to achieve the rolled-up averages, its necessary to calculate;

  • The number of raw data points required for that average (eg to be able to calculate a 5 min average)
  • The number of those averages to store (eg to be able to have a day's worth of 5 min average data)

Its also necessary to calculate how much raw data you want to store (if any)

  • Raw
    • Data is available every 20 secs
    • Therefore 3 intervals per min
    • Therefore 3 x 60 = 180 raw data points per hour
    • Therefore 12 x 180 = 2160 raw data points (to provide 12 hrs of data)
  • Daily
    • 5 min average = 5 x 60 / 20 = 15 raw data points in each average
    • 24 hr coverage = 24 x 60 = 1440 mins => 1440 / 5 = 288 averaged data points
  • Weekly
    • 20 min average = 20 x 60 / 20 = 60 raw data points in each average
    • 7 days coverage = 7 x 24 x 60 = 10,080 mins => 10,080 / 20 = 504 averaged data points
  • Monthly
    • 1 hr average = 60 x 60 / 20 = 180 raw data points in each average
    • 31 day coverage = 31 x 24 x 60 = 44,640 mins => 44,640 / 60 = 744 averaged data points
  • Yearly
    • 1 day average = 24 x 60 x 60 / 20 = 4,320 raw data points in each average
    • 366 day coverage = 366 x 24 x 60 = 527,040 mins = 527,040 / 24 x 60 = 366 averaged data points

The format of the create command is shown here http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html, for the above example this becomes

rrdtool create svr-cpu.rrd --step 20 \                    # Filename and raw data point interval
		DS:CPU-Aggregate:GAUGE:40:0:100 \         # The Datasource: name, type, max interval, min value, max value
		RRA:AVERAGE:0.5:1:2160 \                  # Raw data 'averaged' over 1 data point, ie raw data
		RRA:AVERAGE:0.25:15:288 \                 # Raw data averaged over 15 data points, 288 averages stored
		RRA:MIN:0.25:15:288 \                     # Minimum value of raw data over 15 data points, 288 mins stored
		RRA:MAX:0.25:15:288 \                     # Maximum value of raw data over 15 data points, 288 maxs stored
		RRA:AVERAGE:0.25:60:504 \
		RRA:MIN:0.25:60:504 \
		RRA:MAX:0.25:60:504 \
		RRA:AVERAGE:0.25:180:744 \
		RRA:MIN:0.25:180:744 \
		RRA:MAX:0.25:180:744 \
		RRA:AVERAGE:0.25:4320:366 \
		RRA:MIN:0.25:4320:366 \
		RRA:MAX:0.25:4320:366

Update Database

The following updates an RRD file with a number of (one or more) time:value pairs. The number of pairs is limited by the maximum command length the calling script can handle. Time should be in Unix seconds since Epoch (1/1/1970 00:00:00 UTC) format (you'll need to account for daylight savings if converting from a local time value).

rrdtool update svr-cpu.rrd 1268138780:3.99 1268138800:4.16 1268138820:3.33 1268138840:3.94

It can be useful to know when an RRD was last updated (eg so your script knows where its meant to be updating from, though this should be an interval later than the time returned). Note that if you've defined more than one dataset in an RRD then you'll get the latest update if the DSs aren't being updated in sync.

rrdtool last svr-cpu.rrd

Retrieve From Database

Graphing

At minimum, you need to define the RRD from which you're going to plot data, a DEF (a data source definition), and a LINE (how to plot the data). The graph function assumes you want to plot for data in the RRD from 1 day ago to now.

rrdtool graph graph.png DEF:cpu=svr-cpu.rrd:ds:AVERAGE LINE1:cpu#0000FF:"cpu usage"


Weekly with min and max lines

rrdtool graph graph-week.png --width 500 --height 100 --start end-1w 
   DEF:av=data\svr-cpu.usage.rrd:ds:AVERAGE 
   DEF:min=data\svr-cpu.usage.rrd:ds:MIN 
   DEF:max=data\svr-cpu.usage.rrd:ds:MAX 
   LINE1:av#FF00FF:"cpu usage" 
   LINE2:min#0000FF:"min" 
   LINE3:max#0000FF:"peak


PHP

http://www.ioncannon.net/system-administration/59/php-rrdtool-tutorial/