1RRDs(3)               User Contributed Perl Documentation              RRDs(3)
2
3
4

NAME

6       RRDs - Access RRDtool as a shared module
7

SYNOPSIS

9         use RRDs;
10         RRDs::error
11         RRDs::last ...
12         RRDs::info ...
13         RRDs::create ...
14         RRDs::update ...
15         RRDs::updatev ...
16         RRDs::graph ...
17         RRDs::fetch ...
18         RRDs::tune ...
19         RRDs::times(start, end)
20         RRDs::dump ...
21         RRDs::restore ...
22         RRDs::flushcached ...
23         RRDs::register_fetch_cb ...
24         $RRDs::VERSION
25

DESCRIPTION

27   Calling Sequence
28       This module accesses RRDtool functionality directly from within Perl.
29       The arguments to the functions listed in the SYNOPSIS are explained in
30       the regular RRDtool documentation. The command line call
31
32        rrdtool update mydemo.rrd --template in:out N:12:13
33
34       gets turned into
35
36        RRDs::update ("mydemo.rrd", "--template", "in:out", "N:12:13");
37
38       Note that
39
40        --template=in:out
41
42       is also valid.
43
44       The RRDs::times function takes two parameters:  a "start" and "end"
45       time.  These should be specified in the AT-STYLE TIME SPECIFICATION
46       format used by RRDtool.  See the rrdfetch documentation for a detailed
47       explanation on how to specify time.
48
49   Error Handling
50       The RRD functions will not abort your program even when they can not
51       make sense out of the arguments you fed them.
52
53       The function RRDs::error should be called to get the error status after
54       each function call. If RRDs::error does not return anything then the
55       previous function has completed its task successfully.
56
57        use RRDs;
58        RRDs::update ("mydemo.rrd","N:12:13");
59        my $ERR=RRDs::error;
60        die "ERROR while updating mydemo.rrd: $ERR\n" if $ERR;
61
62   Return Values
63       The functions RRDs::last, RRDs::graph, RRDs::info, RRDs::fetch and
64       RRDs::times return their findings.
65
66       RRDs::last returns a single INTEGER representing the last update time.
67
68        $lastupdate = RRDs::last ...
69
70       RRDs::graph returns an ARRAY containing the x-size and y-size of the
71       created image and a pointer to an array with the results of the PRINT
72       arguments.
73
74        ($result_arr,$xsize,$ysize) = RRDs::graph ...
75        print "Imagesize: ${xsize}x${ysize}\n";
76        print "Averages: ", (join ", ", @$averages);
77
78       RRDs::info returns a pointer to a hash. The keys of the hash represent
79       the property names of the RRD and the values of the hash are the values
80       of the properties.
81
82        $hash = RRDs::info "example.rrd";
83        foreach my $key (keys %$hash){
84          print "$key = $$hash{$key}\n";
85        }
86
87       RRDs::graphv takes the same parameters as RRDs::graph but it returns a
88       pointer to hash. The hash returned contains meta information about the
89       graph. Like its size as well as the position of the graph area on the
90       image.  When calling with and empty filename than the contents of the
91       graph will be returned in the hash as well (key 'image').
92
93       RRDs::updatev also returns a pointer to hash. The keys of the hash are
94       concatenated strings of a timestamp, RRA index, and data source name
95       for each consolidated data point (CDP) written to disk as a result of
96       the current update call. The hash values are CDP values.
97
98       RRDs::fetch is the most complex of the pack regarding return values.
99       There are 4 values. Two normal integers, a pointer to an array and a
100       pointer to a array of pointers.
101
102         my ($start,$step,$names,$data) = RRDs::fetch ...
103         print "Start:       ", scalar localtime($start), " ($start)\n";
104         print "Step size:   $step seconds\n";
105         print "DS names:    ", join (", ", @$names)."\n";
106         print "Data points: ", $#$data + 1, "\n";
107         print "Data:\n";
108         for my $line (@$data) {
109           print "  ", scalar localtime($start), " ($start) ";
110           $start += $step;
111           for my $val (@$line) {
112             printf "%12.1f ", $val;
113           }
114           print "\n";
115         }
116
117       RRDs::xport exposes the rrdxport functionality and returns data with
118       the following structure:
119
120         my ($start,$end,$step,$cols,$names,$data) = RRDs::xport ...
121
122         # $start : timestamp
123         # $end   : timestamp
124         # $step  : seconds
125         # $cols  : number of returned columns
126         # $names : arrayref with the names of the columns
127         # $data  : arrayref of arrayrefs with the data (first index is time, second is column)
128
129       RRDs::times returns two integers which are the number of seconds since
130       epoch (1970-01-01) for the supplied "start" and "end" arguments,
131       respectively.
132
133       See the examples directory for more ways to use this extension.
134
135   Fetch Callback Function
136       Normally when using graph, xport or fetch the data you see will come
137       from an actual rrd file.  Some people who like the look of rrd charts,
138       therefore export their data from a database and then load it into an
139       rrd file just to be able to call rrdgraph on it. Using a custom
140       callback, you can supply your own code for handling the data requests
141       from graph, xport and fetch.
142
143       Todo this, you have to first write a fetch function in perl, and then
144       register this function using "RRDs::fetch_register_callback".
145
146       Finally you can use the pseudo path name cb//[filename] to tell rrdtool
147       to use your callback routine instead of the normal rrdtool fetch
148       function to organize the data required.
149
150       The callback function must look like this:
151
152         sub fetch_callback {
153             my $args_hash = shift;
154             # {
155             #  filename => 'cb//somefilename',
156             #  cd => 'AVERAGE',
157             #  start => 1401295291,
158             #  end => 1401295591,
159             #  step => 300 }
160
161             # do some clever thing to get that data ready
162
163             return {
164                 start => $unix_timestamp,
165                 step => $step_width,
166                 data => {
167                     dsName1 => [ value1, value2, ... ],
168                     dsName2 => [ value1, value2, ... ],
169                     dsName3 => [ value1, value2, ... ],
170                 }
171            };
172         }
173

NOTE

175       If you are manipulating the TZ variable you should also call the POSIX
176       function tzset(3) to initialize all internal state of the library for
177       properly operating in the timezone of your choice.
178
179        use POSIX qw(tzset);
180        $ENV{TZ} = 'CET';
181        POSIX::tzset();
182

AUTHOR

184       Tobias Oetiker <tobi@oetiker.ch>
185
186
187
188perl v5.26.3                      2019-05-14                           RRDs(3)
Impressum