Accesssing RRD Databases

From Qt Wiki
Revision as of 18:59, 30 April 2016 by Simow (talk | contribs) (rrd_fetch parameter description)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


If you are someone who is curious about what your server does when you are not watching, what the CPU load of your build bot is or at what time of the day the network traffic bursts your pipes you are surely running some kind of tool that fills a RRD Database. The de-facto standard is the rrdtool that can be obtained from From their website: RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. RRDtool can be easily integrated in shell scripts, perl, python, ruby, lua or tcl applications.

There are several daemons that can be used to fill the RRD database like collectd, etc. But that shall not be the topic here.

This article is about accessing the RRD Database, fetch data and display them in a QChart

Install RRDtool

Either head to the rrdtool homepage, download and build the package yourself or instruct your package manager to install it.

Depending on your distro you may need to install the development package. Either way you should end up with the include file /usr/include/rrd.h and the libraries /usr/lib/ The latter one is for threaded access using the _th suffixed functions.

Prepare your .pro Project file

If you use the qmake build system just add the line

LIBS += -lrrd_th

Accessing the Data

Calling man librrd reveals some function definitions and how to call them. But none of them fits our purpose: Fetching data. A short google search tells us that most of the API functions are implemented in rrdtool with the same argument count and order. Unfortunately the documentation is very sparse on this so that we have to RTFS instead of RTFM.

Searching the main API header rrd.h for an appropriate function that might serve our needs we stumble upon the following definition in the main header:

int rrd_fetch_r (

   const char *filename,
   const char *cf,
   time_t *start,
   time_t *end,
   unsigned long *step,
   unsigned long *ds_cnt,
   char ***ds_namv,
   rrd_value_t **data);

The parameters are as follows:

  • filename const char pointer to the absolute path of the RRD file
  • cf consolidation function
  • start start time epoch (seconds since Jan 1st 1970)
  • end end time epoch