Code

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