Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Accesssing RRD Databases: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(initial edit)
 
(rrd_fetch parameter description)
 
(One intermediate revision by the same user not shown)
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>
Line 23: Line 23:
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.
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 <tt>rrd.h</tt> for an appropriate function that might serve our needs we stumble upon this:
Searching the main API header <tt>rrd.h</tt> for an appropriate function that might serve our needs we stumble upon the following definition in the main header:


<code>
<code>
Line 36: Line 36:
     rrd_value_t **data);
     rrd_value_t **data);
</code>
</code>
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

Latest revision as of 18:59, 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 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