Introduced a alternated interface to rrd_graph using rrd_info style return
[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.299907080300;
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
37 =head1 DESCRIPTION
38
39 =head2 Calling Sequence
40
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
44
45  rrdtool update mydemo.rrd --template in:out N:12:13
46
47 gets turned into
48
49  RRDs::update ("mydemo.rrd", "--template", "in:out", "N:12:13");
50
51 Note that
52
53  --template=in:out
54
55 is also valid.
56
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.
61
62 =head2 Error Handling
63
64 The RRD functions will not abort your program even when they can not make
65 sense out of the arguments you fed them.
66
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.
70
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;
75
76 =head2 Return Values
77
78 The functions RRDs::last, RRDs::graph, RRDs::info, RRDs::fetch and RRDs::times
79 return their findings.
80
81 B<RRDs::last> returns a single INTEGER representing the last update time.
82
83  $lastupdate = RRDs::last ...
84
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.
87
88  ($averages,$xsize,$ysize) = RRDs::graph ...
89  print "Imagesize: ${xsize}x${ysize}\n";
90  print "Averages: ", (join ", ", @$averages);
91
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.  
95
96  $hash = RRDs::info "example.rrd";
97  foreach my $key (keys %$hash){
98    print "$key = $$hash{$key}\n";
99  }
100
101 B<RRDs::graphv> takes the same paramters as B<RRDs::graph> but it returns a
102 pointer to hash. The hash returned contains meta information about the
103 graph. Like its size as well as the position of the graph area on the image.
104 When calling with and empty filename than the contents of the graph will be
105 returned in the hash as well (key 'image').
106
107 B<RRDs::updatev> also returns a pointer to hash. The keys of the hash
108 are concatenated strings of a timestamp, RRA index, and data source name for
109 each consolidated data point (CDP) written to disk as a result of the
110 current update call. The hash values are CDP values.
111
112 B<RRDs::fetch> is the most complex of
113 the pack regarding return values. There are 4 values. Two normal
114 integers, a pointer to an array and a pointer to a array of pointers.
115
116   my ($start,$step,$names,$data) = RRDs::fetch ... 
117   print "Start:       ", scalar localtime($start), " ($start)\n";
118   print "Step size:   $step seconds\n";
119   print "DS names:    ", join (", ", @$names)."\n";
120   print "Data points: ", $#$data + 1, "\n";
121   print "Data:\n";
122   foreach my $line (@$data) {
123     print "  ", scalar localtime($start), " ($start) ";
124     $start += $step;
125     foreach my $val (@$line) {
126       printf "%12.1f ", $val;
127     }
128     print "\n";
129   }
130
131 B<RRDs::times> returns two integers which are the number of seconds since
132 epoch (1970-01-01) for the supplied "start" and "end" arguments, respectively.
133
134 See the examples directory for more ways to use this extension.
135
136 =head1 NOTE
137
138 If you are manipulating the TZ variable you should also call the posixs
139 function tzset to initialize all internal state of the library for properly
140 operating in the timezone of your choice.
141
142  use POSIX qw(tzset);
143  $ENV{TZ} = 'CET';   
144  POSIX::tzset();     
145
146
147 =head1 AUTHOR
148
149 Tobias Oetiker E<lt>tobi@oetiker.chE<gt>
150
151 =cut