Code

prepare for the release of rrdtool-1.2.5
[rrdtool.git] / bindings / perl-shared / RRDs.pm
1 package RRDs;
3 use strict;
4 use vars qw(@ISA $VERSION);
6 @ISA = qw(DynaLoader);
8 require DynaLoader;
10 $VERSION=1.2005;
12 bootstrap RRDs $VERSION;
14 1;
15 __END__
17 =head1 NAME
19 RRDs - Access RRDtool as a shared module
21 =head1 SYNOPSIS
23   use RRDs;
24   RRDs::error
25   RRDs::last ...
26   RRDs::info ...
27   RRDs::create ...
28   RRDs::update ...
29   RRDs::updatev ...
30   RRDs::graph ...
31   RRDs::fetch ...
32   RRDs::tune ...
33   RRDs::times(start, end)
35 =head1 DESCRIPTION
37 =head2 Calling Sequence
39 This module accesses RRDtool functionality directly from within perl. The
40 arguments to the functions listed in the SYNOPSIS are explained in the regular
41 RRDtool documentation. The commandline call
43  rrdtool update mydemo.rrd --template in:out N:12:13
45 gets turned into
47  RRDs::update ("mydemo.rrd", "--template", "in:out", "N:12:13");
49 Note that
51  --template=in:out
53 is also valid.
55 The RRDs::times function takes two parameters:  a "start" and "end" time.
56 These should be specified in the B<AT-STYLE TIME SPECIFICATION> format
57 used by RRDtool.  See the B<rrdfetch> documentation for a detailed
58 explanation on how to specify time.
60 =head2 Error Handling
62 The RRD functions will not abort your program even when they can not make
63 sense out of the arguments you fed them.
65 The function RRDs::error should be called to get the error status
66 after each function call. If RRDs::error does not return anything
67 then the previous function has completed its task successfully.
69  use RRDs;
70  RRDs::update ("mydemo.rrd","N:12:13");
71  my $ERR=RRDs::error;
72  die "ERROR while updating mydemo.rrd: $ERR\n" if $ERR;
74 =head2 Return Values
76 The functions RRDs::last, RRDs::graph, RRDs::info, RRDs::fetch and RRDs::times
77 return their findings.
79 B<RRDs::last> returns a single INTEGER representing the last update time.
81  $lastupdate = RRDs::last ...
83 B<RRDs::graph> returns an pointer to an ARRAY containing the x-size and y-size of the
84 created image and results of the PRINT arguments.
86  ($averages,$xsize,$ysize) = RRDs::graph ...
87  print "Imagesize: ${xsize}x${ysize}\n";
88  print "Averages: ", (join ", ", @$averages);
90 B<RRDs::info> returns a pointer to a hash. The keys of the hash
91 represent the property names of the RRD and the values of the hash are
92 the values of the properties.  
94  $hash = RRDs::info "example.rrd";
95  foreach my $key (keys %$hash){
96    print "$key = $$hash{$key}\n";
97  }
99 B<RRDs::updatev> also returns a pointer to hash. The keys of the hash
100 are concatenated strings of a timestamp, RRA index, and data source name for
101 each consolidated data point (CDP) written to disk as a result of the
102 current update call. The hash values are CDP values.
104 B<RRDs::fetch> is the most complex of
105 the pack regarding return values. There are 4 values. Two normal
106 integers, a pointer to an array and a pointer to a array of pointers.
108   my ($start,$step,$names,$data) = RRDs::fetch ... 
109   print "Start:       ", scalar localtime($start), " ($start)\n";
110   print "Step size:   $step seconds\n";
111   print "DS names:    ", join (", ", @$names)."\n";
112   print "Data points: ", $#$data + 1, "\n";
113   print "Data:\n";
114   foreach my $line (@$data) {
115     print "  ", scalar localtime($start), " ($start) ";
116     $start += $step;
117     foreach my $val (@$line) {
118       printf "%12.1f ", $val;
119     }
120     print "\n";
121   }
123 B<RRDs::times> returns two integers which are the number of seconds since
124 epoch (1970-01-01) for the supplied "start" and "end" arguments, respectively.
126 See the examples directory for more ways to use this extension.
128 =head1 NOTE
130 If you are manipulating the TZ variable you should also call the posixs
131 function tzset to initialize all internal state of the library for properly
132 operating in the timezone of your choice.
134  use POSIX qw(tzset);
135  $ENV{TZ} = 'CET';   
136  POSIX::tzset();     
139 =head1 AUTHOR
141 Tobias Oetiker E<lt>oetiker@ee.ethz.chE<gt>
143 =cut