.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "RRDs 3" .TH RRDs 3 2024-04-05 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME RRDs \- Access RRDtool as a shared module .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 10 \& use RRDs; \& RRDs::error \& RRDs::last ... \& RRDs::info ... \& RRDs::create ... \& RRDs::update ... \& RRDs::updatev ... \& RRDs::graph ... \& RRDs::fetch ... \& RRDs::tune ... \& RRDs::times(start, end) \& RRDs::dump ... \& RRDs::restore ... \& RRDs::flushcached ... \& RRDs::register_fetch_cb ... \& $RRDs::VERSION .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" .SS "Calling Sequence" .IX Subsection "Calling Sequence" This module accesses RRDtool functionality directly from within Perl. The arguments to the functions listed in the SYNOPSIS are explained in the regular RRDtool documentation. The command line call .PP .Vb 1 \& rrdtool update mydemo.rrd \-\-template in:out N:12:13 .Ve .PP gets turned into .PP .Vb 1 \& RRDs::update ("mydemo.rrd", "\-\-template", "in:out", "N:12:13"); .Ve .PP Note that .PP .Vb 1 \& \-\-template=in:out .Ve .PP is also valid. .PP The RRDs::times function takes two parameters: a "start" and "end" time. These should be specified in the \fBAT-STYLE TIME SPECIFICATION\fR format used by RRDtool. See the \fBrrdfetch\fR documentation for a detailed explanation on how to specify time. .SS "Error Handling" .IX Subsection "Error Handling" The RRD functions will not abort your program even when they cannot make sense out of the arguments you fed them. .PP The function RRDs::error should be called to get the error status after each function call. If RRDs::error does not return anything then the previous function has completed its task successfully. .PP .Vb 4 \& use RRDs; \& RRDs::update ("mydemo.rrd","N:12:13"); \& my $ERR=RRDs::error; \& die "ERROR while updating mydemo.rrd: $ERR\en" if $ERR; .Ve .SS "Return Values" .IX Subsection "Return Values" The functions RRDs::last, RRDs::graph, RRDs::info, RRDs::fetch and RRDs::times return their findings. .PP \&\fBRRDs::last\fR returns a single INTEGER representing the last update time. .PP .Vb 1 \& $lastupdate = RRDs::last ... .Ve .PP \&\fBRRDs::graph\fR returns an ARRAY containing the x\-size and y\-size of the created image and a pointer to an array with the results of the PRINT arguments. .PP .Vb 3 \& ($result_arr,$xsize,$ysize) = RRDs::graph ... \& print "Imagesize: ${xsize}x${ysize}\en"; \& print "Averages: ", (join ", ", @$averages); .Ve .PP \&\fBRRDs::info\fR returns a pointer to a hash. The keys of the hash represent the property names of the RRD and the values of the hash are the values of the properties. .PP .Vb 4 \& $hash = RRDs::info "example.rrd"; \& foreach my $key (keys %$hash){ \& print "$key = $$hash{$key}\en"; \& } .Ve .PP \&\fBRRDs::graphv\fR takes the same parameters as \fBRRDs::graph\fR but it returns a pointer to hash. The hash returned contains meta information about the graph. Like its size as well as the position of the graph area on the image. When calling with '\-' as the filename then the contents of the graph will be returned in the hash as well (key 'image'). .PP \&\fBRRDs::updatev\fR also returns a pointer to hash. The keys of the hash are concatenated strings of a timestamp, RRA index, and data source name for each consolidated data point (CDP) written to disk as a result of the current update call. The hash values are CDP values. .PP \&\fBRRDs::fetch\fR is the most complex of the pack regarding return values. There are 4 values. Two normal integers, a pointer to an array and a pointer to an array of pointers. .PP .Vb 10 \& my ($start,$step,$names,$data) = RRDs::fetch ... \& print "Start: ", scalar localtime($start), " ($start)\en"; \& print "Step size: $step seconds\en"; \& print "DS names: ", join (", ", @$names)."\en"; \& print "Data points: ", $#$data + 1, "\en"; \& print "Data:\en"; \& for my $line (@$data) { \& print " ", scalar localtime($start), " ($start) "; \& $start += $step; \& for my $val (@$line) { \& printf "%12.1f ", $val; \& } \& print "\en"; \& } .Ve .PP \&\fBRRDs::xport\fR exposes the rrdxport functionality and returns data with the following structure: .PP .Vb 1 \& my ($start,$end,$step,$cols,$names,$data) = RRDs::xport ... \& \& # $start : timestamp \& # $end : timestamp \& # $step : seconds \& # $cols : number of returned columns \& # $names : arrayref with the names of the columns \& # $data : arrayref of arrayrefs with the data (first index is time, second is column) .Ve .PP \&\fBRRDs::times\fR returns two integers which are the number of seconds since epoch (1970\-01\-01) for the supplied "start" and "end" arguments, respectively. .PP See the examples directory for more ways to use this extension. .SS "Fetch Callback Function" .IX Subsection "Fetch Callback Function" Normally when using graph, xport or fetch the data you see will come from an actual rrd file. Some people who like the look of rrd charts, therefore export their data from a database and then load it into an rrd file just to be able to call rrdgraph on it. Using a custom callback, you can supply your own code for handling the data requests from graph, xport and fetch. .PP To do this, you have to first write a fetch function in perl, and then register this function using \f(CW\*(C`RRDs::fetch_register_callback\*(C'\fR. .PP Finally you can use the pseudo path name \fBcb//\fR[\fIfilename\fR] to tell rrdtool to use your callback routine instead of the normal rrdtool fetch function to organize the data required. .PP The callback function must look like this: .PP .Vb 8 \& sub fetch_callback { \& my $args_hash = shift; \& # { \& # filename => \*(Aqcb//somefilename\*(Aq, \& # cd => \*(AqAVERAGE\*(Aq, \& # start => 1401295291, \& # end => 1401295591, \& # step => 300 } \& \& # do some clever thing to get that data ready \& \& return { \& start => $unix_timestamp, \& step => $step_width, \& data => { \& dsName1 => [ value1, value2, ... ], \& dsName2 => [ value1, value2, ... ], \& dsName3 => [ value1, value2, ... ], \& } \& }; \& } .Ve .SH NOTE .IX Header "NOTE" If you are manipulating the TZ variable you should also call the POSIX function \fBtzset\fR\|(3) to initialize all internal states of the library for properly operating in the timezone of your choice. .PP .Vb 3 \& use POSIX qw(tzset); \& $ENV{TZ} = \*(AqCET\*(Aq; \& POSIX::tzset(); .Ve .SH AUTHOR .IX Header "AUTHOR" Tobias Oetiker