Code

44b4d8cfc0277a4847e26dd89746213da4d56d79
[pkg-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.2027;
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)
34   RRDs::dump ...
35   RRDs::restore ...
37 =head1 DESCRIPTION
39 =head2 Calling Sequence
41 This module accesses RRDtool functionality directly from within perl. The
42 arguments to the functions listed in the SYNOPSIS are explained in the regular
43 RRDtool documentation. The commandline call
45  rrdtool update mydemo.rrd --template in:out N:12:13
47 gets turned into
49  RRDs::update ("mydemo.rrd", "--template", "in:out", "N:12:13");
51 Note that
53  --template=in:out
55 is also valid.
57 The RRDs::times function takes two parameters:  a "start" and "end" time.
58 These should be specified in the B<AT-STYLE TIME SPECIFICATION> format
59 used by RRDtool.  See the B<rrdfetch> documentation for a detailed
60 explanation on how to specify time.
62 =head2 Error Handling
64 The RRD functions will not abort your program even when they can not make
65 sense out of the arguments you fed them.
67 The function RRDs::error should be called to get the error status
68 after each function call. If RRDs::error does not return anything
69 then the previous function has completed its task successfully.
71  use RRDs;
72  RRDs::update ("mydemo.rrd","N:12:13");
73  my $ERR=RRDs::error;
74  die "ERROR while updating mydemo.rrd: $ERR\n" if $ERR;
76 =head2 Return Values
78 The functions RRDs::last, RRDs::graph, RRDs::info, RRDs::fetch and RRDs::times
79 return their findings.
81 B<RRDs::last> returns a single INTEGER representing the last update time.
83  $lastupdate = RRDs::last ...
85 B<RRDs::graph> returns an pointer to an ARRAY containing the x-size and y-size of the
86 created image and results of the PRINT arguments.
88  ($averages,$xsize,$ysize) = RRDs::graph ...
89  print "Imagesize: ${xsize}x${ysize}\n";
90  print "Averages: ", (join ", ", @$averages);
92 B<RRDs::info> returns a pointer to a hash. The keys of the hash
93 represent the property names of the RRD and the values of the hash are
94 the values of the properties.  
96  $hash = RRDs::info "example.rrd";
97  foreach my $key (keys %$hash){
98    print "$key = $$hash{$key}\n";
99  }
101 B<RRDs::updatev> also returns a pointer to hash. The keys of the hash
102 are concatenated strings of a timestamp, RRA index, and data source name for
103 each consolidated data point (CDP) written to disk as a result of the
104 current update call. The hash values are CDP values.
106 B<RRDs::fetch> is the most complex of
107 the pack regarding return values. There are 4 values. Two normal
108 integers, a pointer to an array and a pointer to a array of pointers.
110   my ($start,$step,$names,$data) = RRDs::fetch ... 
111   print "Start:       ", scalar localtime($start), " ($start)\n";
112   print "Step size:   $step seconds\n";
113   print "DS names:    ", join (", ", @$names)."\n";
114   print "Data points: ", $#$data + 1, "\n";
115   print "Data:\n";
116   foreach my $line (@$data) {
117     print "  ", scalar localtime($start), " ($start) ";
118     $start += $step;
119     foreach my $val (@$line) {
120       printf "%12.1f ", $val;
121     }
122     print "\n";
123   }
125 B<RRDs::times> returns two integers which are the number of seconds since
126 epoch (1970-01-01) for the supplied "start" and "end" arguments, respectively.
128 See the examples directory for more ways to use this extension.
130 =head1 NOTE
132 If you are manipulating the TZ variable you should also call the posixs
133 function tzset to initialize all internal state of the library for properly
134 operating in the timezone of your choice.
136  use POSIX qw(tzset);
137  $ENV{TZ} = 'CET';   
138  POSIX::tzset();     
141 =head1 AUTHOR
143 Tobias Oetiker E<lt>tobi@oetiker.chE<gt>
145 =cut