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