Accesssing RRD Databases: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(initial edit)
 
(wording)
Line 13: Line 13:
Depending on your distro you may need to install the development package. Either way you should end up with the include file <tt>/usr/include/rrd.h</tt> and the libraries <tt>/usr/lib/librrd.so</tt>/<tt>librrd_th.so</tt>. The latter one is for threaded access using the _th suffixed functions.
Depending on your distro you may need to install the development package. Either way you should end up with the include file <tt>/usr/include/rrd.h</tt> and the libraries <tt>/usr/lib/librrd.so</tt>/<tt>librrd_th.so</tt>. The latter one is for threaded access using the _th suffixed functions.


== Prepare your pro file ==
== Prepare your .pro Project file ==
If you use the qmake build system just add the line
If you use the qmake build system just add the line
<pre>
<pre>

Revision as of 18:31, 30 April 2016

Under Construction

Introduction

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 http://rrdtool.org. 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/librrd.so/librrd_th.so. 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 this:

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);