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