Code

45da6e7a27278bf3ae8e16a762301c6e57beb559
[pkg-rrdtool.git] / doc / RRDs.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>RRDs</title>
5 <link rev="made" href="mailto:root@localhost" />
6 </head>
8 <body style="background-color: white">
10 <p><a name="__index__"></a></p>
11 <!-- INDEX BEGIN -->
12 <!--
14 <ul>
16         <li><a href="#name">NAME</a></li>
17         <li><a href="#synopsis">SYNOPSIS</a></li>
18         <li><a href="#description">DESCRIPTION</a></li>
19         <ul>
21                 <li><a href="#calling_sequence">Calling Sequence</a></li>
22                 <li><a href="#error_handling">Error Handling</a></li>
23                 <li><a href="#return_values">Return Values</a></li>
24         </ul>
26         <li><a href="#note">NOTE</a></li>
27         <li><a href="#author">AUTHOR</a></li>
28 </ul>
29 -->
30 <!-- INDEX END -->
32 <p>
33 </p>
34 <h1><a name="name">NAME</a></h1>
35 <p>RRDs - Access RRDtool as a shared module</p>
36 <p>
37 </p>
38 <hr />
39 <h1><a name="synopsis">SYNOPSIS</a></h1>
40 <pre>
41   use RRDs;
42   RRDs::error
43   RRDs::last ...
44   RRDs::info ...
45   RRDs::create ...
46   RRDs::update ...
47   RRDs::updatev ...
48   RRDs::graph ...
49   RRDs::fetch ...
50   RRDs::tune ...
51   RRDs::times(start, end)
52   RRDs::dump ...
53   RRDs::restore ...
54   RRDs::flushcached ...</pre>
55 <p>
56 </p>
57 <hr />
58 <h1><a name="description">DESCRIPTION</a></h1>
59 <p>
60 </p>
61 <h2><a name="calling_sequence">Calling Sequence</a></h2>
62 <p>This module accesses RRDtool functionality directly from within Perl. The
63 arguments to the functions listed in the SYNOPSIS are explained in the regular
64 RRDtool documentation. The command line call</p>
65 <pre>
66  rrdtool update mydemo.rrd --template in:out N:12:13</pre>
67 <p>gets turned into</p>
68 <pre>
69  RRDs::update (&quot;mydemo.rrd&quot;, &quot;--template&quot;, &quot;in:out&quot;, &quot;N:12:13&quot;);</pre>
70 <p>Note that</p>
71 <pre>
72  --template=in:out</pre>
73 <p>is also valid.</p>
74 <p>The RRDs::times function takes two parameters:  a ``start'' and ``end'' time.
75 These should be specified in the <strong>AT-STYLE TIME SPECIFICATION</strong> format
76 used by RRDtool.  See the <strong>rrdfetch</strong> documentation for a detailed
77 explanation on how to specify time.</p>
78 <p>
79 </p>
80 <h2><a name="error_handling">Error Handling</a></h2>
81 <p>The RRD functions will not abort your program even when they can not make
82 sense out of the arguments you fed them.</p>
83 <p>The function RRDs::error should be called to get the error status
84 after each function call. If RRDs::error does not return anything
85 then the previous function has completed its task successfully.</p>
86 <pre>
87  use RRDs;
88  RRDs::update (&quot;mydemo.rrd&quot;,&quot;N:12:13&quot;);
89  my $ERR=RRDs::error;
90  die &quot;ERROR while updating mydemo.rrd: $ERR\n&quot; if $ERR;</pre>
91 <p>
92 </p>
93 <h2><a name="return_values">Return Values</a></h2>
94 <p>The functions RRDs::last, RRDs::graph, RRDs::info, RRDs::fetch and RRDs::times
95 return their findings.</p>
96 <p><strong>RRDs::last</strong> returns a single INTEGER representing the last update time.</p>
97 <pre>
98  $lastupdate = RRDs::last ...</pre>
99 <p><strong>RRDs::graph</strong> returns an ARRAY containing the x-size and y-size of the
100 created image and a pointer to an array with the results of the PRINT arguments.</p>
101 <pre>
102  ($result_arr,$xsize,$ysize) = RRDs::graph ...
103  print &quot;Imagesize: ${xsize}x${ysize}\n&quot;;
104  print &quot;Averages: &quot;, (join &quot;, &quot;, @$averages);</pre>
105 <p><strong>RRDs::info</strong> returns a pointer to a hash. The keys of the hash
106 represent the property names of the RRD and the values of the hash are
107 the values of the properties.</p>
108 <pre>
109  $hash = RRDs::info &quot;example.rrd&quot;;
110  foreach my $key (keys %$hash){
111    print &quot;$key = $$hash{$key}\n&quot;;
112  }</pre>
113 <p><strong>RRDs::graphv</strong> takes the same parameters as <strong>RRDs::graph</strong> but it returns a
114 pointer to hash. The hash returned contains meta information about the
115 graph. Like its size as well as the position of the graph area on the image.
116 When calling with and empty filename than the contents of the graph will be
117 returned in the hash as well (key 'image').</p>
118 <p><strong>RRDs::updatev</strong> also returns a pointer to hash. The keys of the hash
119 are concatenated strings of a timestamp, RRA index, and data source name for
120 each consolidated data point (CDP) written to disk as a result of the
121 current update call. The hash values are CDP values.</p>
122 <p><strong>RRDs::fetch</strong> is the most complex of
123 the pack regarding return values. There are 4 values. Two normal
124 integers, a pointer to an array and a pointer to a array of pointers.</p>
125 <pre>
126   my ($start,$step,$names,$data) = RRDs::fetch ... 
127   print &quot;Start:       &quot;, scalar localtime($start), &quot; ($start)\n&quot;;
128   print &quot;Step size:   $step seconds\n&quot;;
129   print &quot;DS names:    &quot;, join (&quot;, &quot;, @$names).&quot;\n&quot;;
130   print &quot;Data points: &quot;, $#$data + 1, &quot;\n&quot;;
131   print &quot;Data:\n&quot;;
132   for my $line (@$data) {
133     print &quot;  &quot;, scalar localtime($start), &quot; ($start) &quot;;
134     $start += $step;
135     for my $val (@$line) {
136       printf &quot;%12.1f &quot;, $val;
137     }
138     print &quot;\n&quot;;
139   }</pre>
140 <p><strong>RRDs::times</strong> returns two integers which are the number of seconds since
141 epoch (1970-01-01) for the supplied ``start'' and ``end'' arguments, respectively.</p>
142 <p>See the examples directory for more ways to use this extension.</p>
143 <p>
144 </p>
145 <hr />
146 <h1><a name="note">NOTE</a></h1>
147 <p>If you are manipulating the TZ variable you should also call the POSIX
148 function <em>tzset(3)</em> to initialize all internal state of the library for properly
149 operating in the timezone of your choice.</p>
150 <pre>
151  use POSIX qw(tzset);
152  $ENV{TZ} = 'CET';   
153  POSIX::tzset();</pre>
154 <p>
155 </p>
156 <hr />
157 <h1><a name="author">AUTHOR</a></h1>
158 <p>Tobias Oetiker &lt;<a href="mailto:tobi@oetiker.ch">tobi@oetiker.ch</a>&gt;</p>
160 </body>
162 </html>