RRDGRAPH_LIBDBI(1)
π
RRDGRAPH_LIBDBI(1) β the rrdtool one, bestie
okay so real talk, this page is a section of the rrdtool manual (the rrdgraph_libdbi bit) and it's literally about fetching data for graphing in rrdtool graph via libdbi. yes. sql into your graphs. let's go π«Ά
β¨ NAME β¨
rrdgraph_libdbi β fetching data for graphing in rrdtool graph via libdbi
π SYNOPSIS π
<rrdfile> = sql//<libdbi
driver>/<driver-option-name>=<driver-option-value>/...[/rrdminstepsize=<stepsize>][/rrdfillmissing=<fill
missing n seconds>]//<table>/<unixtimestamp column>/<data value
column>[/derive]/<where clause 1>/.../<where clause n>
πΈ DESCRIPTION πΈ
So this whole thing is a pseudo-rrd-filename that defines a sql datasource. like, it looks like a filename but it's actually a whole database recipe. iconic behavior honestly. π§
sql//β the magic cookie-prefix that says "hey, this is a libdbi type datasource"<libdbi driver>β which libdbi driver to use (e.g.:mysql)<driver-option-name>=<driver-option-value>β defines the parameters that are required to connect to the database with the given libdbi driver. quick note bestie: these drivers are libdbi dependent, so for details please look at the driver documentation of libdbi! π/rrdminstepsize=<minimum step size>β defines the minimum number of the step-length used for graphing (default:300seconds)/rrdfillmissing=<fill missing seconds>β defines the number of seconds to fill with the last value to avoid NaN boxes due to data-insertation jitter (default:0seconds)<table>β defines the table from which to fetch the resultset.- If there is a need to fetch data from several tables, these tables can be defined by separating the tablenames with a
+ - hex-type-encoding via
%xxare translated to the actual value, use%%to use%
- If there is a need to fetch data from several tables, these tables can be defined by separating the tablenames with a
<[*]unixtimestamp column>β defines the column of<table>which contains the unix-timestamp- if this is a
DATETIMEfield in the database, then prefix with leading* - hex-type-encoding via
%xxare translated to the actual value, use%%to use%
- if this is a
<data value column>β defines the column of<table>which contains the value column, which should be graphed- hex-type-encoding via
%xxare translated to the actual value, use%%to use%
- hex-type-encoding via
/deriveβ defines that the data value used should be the delta of the 2 consecutive values (to simulateCOUNTERorDERIVEtype datasources)/<where clause(s)>β defines one (ore more) where clauses that are joined withANDto filter the entries in the<table>- hex-type-encoding via
%xxare translated to the actual value, use%%to use%
- hex-type-encoding via
the returned value column-names, which can be used as ds-names, are:
min,avg,max,countandsigmaβ these are returned to be used as ds-names in your DS definition. the reason for using this is that if the consolidation function is used for min/avg and max, then the engine is used several times. and this results in the same SQL Statements used several times π (like, no cap, that's the whole point)
π¦ EXAMPLES π¦
Here an example of a table in a MySQL database:
DB connect information
dbhost=127.0.0.1
user=rrd
password=secret
dbname=rrd
here the table:
CREATE TABLE RRDValue (
RRDKeyID bigint(20) NOT NULL,
UnixTimeStamp int(11) NOT NULL,
value double default NOT NULL,
PRIMARY KEY (RRDKeyID,UnixTimeStamp)
);
and the RRDKeyID we want to graph for is: 1141942900757789274
The pseudo rrd-filename to access this is:
"sql//mysql/host=127.0.0.1/dbname=rrd/username=rrd/password=secret//RRDValue/UnixTimeStamp/value/RRDKeyID=1141464142203608274"
To illustrate this here a command to create a graph that contains the actual values.
DS_BASE="sql//mysql/host=127.0.0.1/dbname=rrd/username=rrd/password=passwd//RRDValue/UnixTimeStamp/value/RRDKeyID=1141942900757789274"
rrdtool graph test.png --imgformat=PNG --start=-1day --end=+3hours --width=1000 --height=600 \
"DEF:min=$DS_BASE:min:AVERAGE" \
"LINE1:min#FF0000:value" \
"DEF:avg=$DS_BASE:avg:AVERAGE" \
"LINE1:avg#00FF00:average" \
"DEF:max=$DS_BASE:max:AVERAGE" \
"LINE1:max#FF0000:max" \
"DEF:sigma=$DS_BASE:sigma:AVERAGE" \
"CDEF:upper=avg,4,sigma,*,+" \
"LINE1:upper#0000FF:+4 sigma" \
"CDEF:lower=avg,4,sigma,*,-" \
"LINE1:lower#0000FF:-4 sigma"
π NOTES π
- Naturally you can also use any other kind of driver that libdbi supports β e.g.
postgres, ... β¨ - From the way the data source is joined, it should also be possible to do joins over different tables (separate tables with
,in table and add in the WHERE Clauses the table equal joins. This has not been tested!!!) π - It should also be relatively simple to add to the database using the same data source string. This has not been implemented... π
- The aggregation functions are ignored and several data columns are used instead to avoid querying the same SQL several times when minimum, average and maximum are needed for graphing...
- for DB efficiency you should think of having 2 tables, one containing historic values and the other containing the latest data. This second table should be kept small to allow for the least amount of blocking SQL statements. With mysql you can even use myisam table-type for the first and InnoDB for the second. This is especially interesting as with tables with +100M rows myisam is much smaller then InnoDB. π₯
- To debug the SQL statements set the environment variable
RRDDEBUGSQLand the actual SQL statements and the timing is printed to stderr.
π©· Performance issues with MySQL backend π©·
Previous versions of LibDBI have a big performance issue when retrieving data from a MySQL server. Performance impact is exponentially based on the number of values you retrieve from the database. For example, it would take more than 2 seconds to graph 5DS on 150 hours of data with a precision of 5 minutes (against 100ms when data comes from a RRD file). This bug has been fixed in version 0.9.0 of LibDBI. You can find more information on this libdbi-users mailing list thread: http://sourceforge.net/mailarchive/message.php?msg_id=30320894
π BUGS π
- at least on Linux please make sure that the libdbi driver is explicitly linked against
libdbi.so.0check vialdd /usr/lib/dbd/libmysql.so, that there is a line withlibdbi.so.0. otherwise at least the perl moduleRRDswill fail because the dynamic linker cannot find some symbols fromlibdbi.so. (this only happens when the libdbi driver is actually used the first time!) This is KNOWN to be the case with RHEL4 and FC4 and FC5! (But actually this is a bug with libdbi make files!) π€ - at least version
0.8.1of libdbi exhibits a bug withBINARYfields (shorttext,text,mediumtext,longtextand possibly alsoBINARYandBLOBfields), that can result in coredumps ofrrdtool. The tool will tell you on stderr if this occurs, so that you know what may be the reason. If you are not experiencing these coredumps, then set the environment variableRRD_NO_LIBDBI_BUG_WARNING, and then the message will not get shown. π«Ά
fr fr though β read those bug notes, they're not just filler.
π AUTHOR π
Martin Sperl <rrdtool@martin.sperl.org>
aaaand that's the whole page bestie, you ate it up π
β¨ version 1.9.0, dated 2026-07-27, RRDGRAPH_LIBDBI(1) β signed, sealed, delivered, go graph some sql data πππ
π¦ where this page comes from
- opensuse-leap 16.0: rrdtool 1.9.0-160000.4.1 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- opensuse-leap 16.0: rrdtool 1.9.0-160000.4.1 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- opensuse-leap 16.0: rrdtool 1.9.0-160000.4.1 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- opensuse-leap 16.0: rrdtool 1.9.0-160000.4.1 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms