1 =head1 NAME
3 rrdgraph_libdbi - fetching data for graphing in rrdtool graph via libdbi
5 =head1 SYNOPSIS
7 E<lt>rrdfileE<gt> = B<sql//E<lt>libdbi driverE<gt>/E<lt>driver-option-nameE<gt>=E<lt>driver-option-valueE<gt>/...[/rrdminstepsize=E<lt>stepsizeE<gt>][/rrdfillmissing=E<lt>fill missing n secondsE<gt>]//E<lt>tableE<gt>/E<lt>unixtimestamp columnE<gt>/E<lt>data value columnE<gt>[/derive]/E<lt>where clause 1E<gt>/.../E<lt>where clause nE<gt>>
9 =head1 DESCRIPTION
11 This pseudo-rrd-filename defines a sql datasource:
13 =over 8
15 =item B<sql//>
17 magic cookie-prefix for a libdbi type datasource
19 =item B<E<lt>libdbi driverE<gt>>
21 which libdbi driver to use (e.g: mysql)
23 =item B<E<lt>driver-option-nameE<gt>>=B<E<lt>driver-option-valueE<gt>>
25 defines the parameters that are required to connect to the database with the given libdbi driver
26 (These drivers are libdbi dependent - for details please look at the driver documentation of libdbi!)
28 =item B</rrdminstepsize>=B<E<lt>minimum step sizeE<gt>>
30 defines the minimum number of the step-length used for graphing (default: 300 seconds)
32 =item B</rrdfillmissing>=B<E<lt>fill missing secondsE<gt>>
34 defines the number of seconds to fill with the last value to avoid NaN boxes due to data-insertation jitter (default: 0 seconds)
36 =item B<E<lt>tableE<gt>>
38 defines the table from which to fetch the resultset.
40 If there is a need to fetch data from several tables, these tables can be defined by separating the tablenames with a "+"
42 hex-type-encoding via %xx are translated to the actual value, use %% to use %
44 =item B<E<lt>[*]unixtimestamp columnE<gt>>
46 defines the column of E<lt>tableE<gt> which contains the unix-timestamp
47 - if this is a DATETIME field in the database, then prefix with leading '*'
49 hex-type-encoding via %xx are translated to the actual value, use %% to use %
51 =item B<E<lt>data value columnE<gt>>
53 defines the column of E<lt>tableE<gt> which contains the value column, which should be graphed
55 hex-type-encoding via %xx are translated to the actual value, use %% to use %
57 =item B</derive>
59 defines that the data value used should be the delta of the 2 consecutive values (to simulate COUNTER or DERIVE type datasources)
61 =item B</E<lt>where clause(s)E<gt>>
63 defines one (ore more) where clauses that are joined with AND to filter the entries in the <lt>table<gt>
65 hex-type-encoding via %xx are translated to the actual value, use %% to use %
67 =back
69 the returned value column-names, which can be used as ds-names, are:
71 =over 8
73 =item B<min>, B<avg>, B<max>, B<count> and B<sigma>
75 are returned to be used as ds-names in your DS definition.
76 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.
77 And this results in the same SQL Statements used several times
79 =back
81 =head1 EXAMPLES
83 Here an example of a table in a MySQL database:
85 DB connect information
86 dbhost=127.0.0.1
87 user=rrd
88 password=secret
89 database=rrd
91 here the table:
92 CREATE TABLE RRDValue (
93 RRDKeyID bigint(20) NOT NULL,
94 UnixTimeStamp int(11) NOT NULL,
95 value double default NOT NULL,
96 PRIMARY KEY (RRDKeyID,UnixTimeStamp)
97 );
99 and the RRDKeyID we want to graph for is: 1141942900757789274
101 The pseudo rrd-filename to access this is:
102 "sql//mysql/host=127.0.0.1/dbname=rrd/username=rrd/password=secret//RRDValue/UnixTimeStamp/value/RRDKeyID=1141464142203608274"
104 To illustrate this here a command to create a graph that contains the actual values.
106 DS_BASE="sql//mysql/host=127.0.0.1/dbname=rrd/username=rrd/password=passwd//RRDValue/UnixTimeStamp/value/RRDKeyID=1141942900757789274"
107 rrdtool graph test.png --imgformat=PNG --start=-1day --end=+3hours --width=1000 --height=600 \
108 "DEF:min=$DS_BASE:min:AVERAGE" \
109 "LINE1:min#FF0000:value" \
110 "DEF:avg=$DS_BASE:avg:AVERAGE" \
111 "LINE1:avg#00FF00:average" \
112 "DEF:max=$DS_BASE:max:AVERAGE" \
113 "LINE1:max#FF0000:max" \
114 "DEF:sigma=$DS_BASE:sigma:AVERAGE" \
115 "CDEF:upper=avg,4,sigma,*,+" \
116 "LINE1:upper#0000FF:+4 sigma" \
117 "CDEF:lower=avg,4,sigma,*,-" \
118 "LINE1:lower#0000FF:-4 sigma"
120 =head1 NOTES
122 * Naturally you can also use any other kind of driver that libdbi supports - e.g postgres, ...
124 * From the way the data source is joined, it should also be possible to do joins over different tables
125 (separate tables with "," in table and add in the WHERE Clauses the table equal joins.
126 This has not been tested!!!)
128 * It should also be relatively simple to add to the database using the same data source string.
129 This has not been implemented...
131 * The aggregation functions are ignored and several data columns are used instead
132 to avoid querying the same SQL several times when minimum, average and maximum are needed for graphing...
134 * for DB efficiency you should think of having 2 tables, one containing historic values and the other containing the latest data.
135 This second table should be kept small to allow for the least ammount of blocking SQL statements.
136 Whith mysql you can even use myisam table-type for the first and InnoDB for the second.
137 This is especially interresting as with tables with +100M rows myisam is much smaller then InnoDB.
139 * To debug the SQL statements set the environment variable RRDDEBUGSQL and the actual SQL statements and the timing is printed to stderr.
141 =head1 BUGS
143 * at least on Linux please make sure that the libdbi driver is explicitly linked against libdbi.so.0
144 check via ldd /usr/lib/dbd/libmysql.so, that there is a line with libdbi.so.0.
145 otherwise at least the perl module RRDs will fail because the dynamic linker can not find some symbols from libdbi.so.
146 (this only happens when the libdbi driver is actually used the first time!)
147 This is KNOWN to be the case with RHEL4 and FC4 and FC5! (But actually this is a bug with libdbi make files!)
149 * at least version 0.8.1 of libdbiexhibits a bug with BINARY fields
150 (shorttext,text,mediumtext,longtext and possibly also BINARY and BLOB fields),
151 that can result in coredumps of rrdtool.
152 The tool will tell you on stderr if this occures, so that you know what may be the reason.
153 If you are not experiencing these coredumps, then set the environment variable RRD_NO_LIBDBI_BUG_WARNING,
154 and then the message will not get shown.
156 =head1 AUTHOR
158 Martin Sperl <rrdtool@martin.sperl.org>