Alternate update interface, updatev. Returns info about CDPs written to disk as resul...
[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.100001;
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
33 =head1 DESCRIPTION
34
35 =head2 Calling Sequence
36
37 This module accesses rrdtool functionality directly from within perl. The
38 arguments to the functions listed in the SYNOPSIS are explained in the regular
39 rrdtool documentation. The commandline call
40
41  rrdtool update mydemo.rrd --template in:out N:12:13
42
43 gets turned into
44
45  RRDs::update ("mydemo.rrd", "--template", "in:out", "N:12:13");
46
47 Note that
48
49  --template=in:out
50
51 is also valid.
52
53
54 =head2 Error Handling
55
56 The RRD functions will not abort your program even when they can not make
57 sense out of the arguments you fed them.
58
59 The function RRDs::error should be called to get the error status
60 after each function call. If RRDs::error does not return anything
61 then the previous function has completed its task successfully.
62
63  use RRDs;
64  RRDs::update ("mydemo.rrd","N:12:13");
65  my $ERR=RRDs::error;
66  die "ERROR while updating mydemo.rrd: $ERR\n" if $ERR;
67
68 =head2 Return Values
69
70 The functions RRDs::last, RRDs::graph, RRDs::info and RRDs::fetch return their
71 findings.
72
73 B<RRDs::last> returns a single INTEGER representing the last update time.
74
75  $lastupdate = RRDs::last ...
76
77 B<RRDs::graph> returns an pointer to an ARRAY containing the x-size and y-size of the
78 created image and results of the PRINT arguments.
79
80  ($averages,$xsize,$ysize) = RRDs::graph ...
81  print "Imagesize: ${xsize}x${ysize}\n";
82  print "Averages: ", (join ", ", @$averages);
83
84 B<RRDs::info> returns a pointer to a hash. The keys of the hash
85 represent the property names of the rrd and the values of the hash are
86 the values of the properties.  
87
88  $hash = RRDs::info "example.rrd";
89  foreach my $key (keys %$hash){
90    print "$key = $$hash{$key}\n";
91  }
92
93 B<RRDs::updatev> also returns a pointer to hash. The keys of the hash
94 are concatenated strings of a timestamp, RRA index, and data source name for
95 each consolidated data point (CDP) written to disk as a result of the
96 current update call. The hash values are CDP values.
97
98 B<RRDs::fetch> is the most complex of
99 the pack regarding return values. There are 4 values. Two normal
100 integers, a pointer to an array and a 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   foreach my $line (@$data) {
109     print "  ", scalar localtime($start), " ($start) ";
110     $start += $step;
111     foreach my $val (@$line) {
112       printf "%12.1f ", $val;
113     }
114     print "\n";
115   }
116
117 See the examples directory for more ways to use this extension.
118
119 =head1 NOTE
120
121 If you are manipulating the TZ variable you should also call the posixs
122 function tzset to initialize all internal state of the library for properly
123 operating in the timezone of your choice.
124
125  use POSIX qw(tzset);
126  $ENV{TZ} = 'CET';   
127  POSIX::tzset();     
128
129
130 =head1 AUTHOR
131
132 Tobias Oetiker E<lt>oetiker@ee.ethz.chE<gt>
133
134 =cut