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