Code

Imported upstream SVN snapshot 1.4~rc2+20090928.
[pkg-rrdtool.git] / doc / rrdcgi.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>rrdcgi</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="#keywords">Keywords</a></li>
26         </ul>
28         <li><a href="#example_1">EXAMPLE 1</a></li>
29         <li><a href="#example_2">EXAMPLE 2</a></li>
30         <li><a href="#example_3">EXAMPLE 3</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>rrdcgi - Create web pages containing RRD graphs based on templates</p>
44 <p>
45 </p>
46 <hr />
47 <h1><a name="synopsis">SYNOPSIS</a></h1>
48 <p><code>#!/path/to/</code><strong>rrdcgi</strong> [<strong>--filter</strong>]</p>
49 <p>
50 </p>
51 <hr />
52 <h1><a name="description">DESCRIPTION</a></h1>
53 <p><strong>rrdcgi</strong> is a sort of very limited script interpreter. Its purpose
54 is to run as a cgi-program and parse a web page template containing special
55 &lt;RRD:: tags. <strong>rrdcgi</strong> will interpret and act according to these tags.
56 In the end it will printout a web page including the necessary CGI headers.</p>
57 <p><strong>rrdcgi</strong> parses the contents of the template in 3 steps. In each step it looks
58 only for a subset of tags. This allows nesting of tags.</p>
59 <p>The argument parser uses the same semantics as you are used from your C-shell.</p>
60 <dl>
61 <dt><strong><a name="filter" class="item"><strong>--filter</strong></a></strong></dt>
63 <dd>
64 <p>Assume that rrdcgi is run as a filter and not as a cgi.</p>
65 </dd>
66 </dl>
67 <p>
68 </p>
69 <h2><a name="keywords">Keywords</a></h2>
70 <dl>
71 <dt><strong><a name="rrd_cv_name" class="item">RRD::CV <em>name</em></a></strong></dt>
73 <dd>
74 <p>Inserts the CGI variable of the given name.</p>
75 </dd>
76 <dt><strong><a name="rrd_cv_quote_name" class="item">RRD::CV::QUOTE <em>name</em></a></strong></dt>
78 <dd>
79 <p>Inserts the CGI variable of the given name but quotes it, ready for
80 use as an argument in another RRD:: tag. So even when there are spaces in the
81 value of the CGI variable it will still be considered to be one argument.</p>
82 </dd>
83 <dt><strong><a name="rrd_cv_path_name" class="item">RRD::CV::PATH <em>name</em></a></strong></dt>
85 <dd>
86 <p>Inserts the CGI variable of the given name, quotes it and makes sure
87 it starts neither with a '/' nor contains '..'. This is to make
88 sure that no problematic pathnames can be introduced through the
89 CGI interface.</p>
90 </dd>
91 <dt><strong><a name="rrd_getenv_variable" class="item">RRD::GETENV <em>variable</em></a></strong></dt>
93 <dd>
94 <p>Get the value of an environment variable.</p>
95 <pre>
96  &lt;RRD::GETENV REMOTE_USER&gt;</pre>
97 <p>might give you the name of the remote user given you are using
98 some sort of access control on the directory.</p>
99 </dd>
100 <dt><strong><a name="rrd_goodfor_seconds" class="item">RRD::GOODFOR <em>seconds</em></a></strong></dt>
102 <dd>
103 <p>Specify the number of seconds this page should remain valid. This will prompt
104 the rrdcgi to output a Last-Modified, an Expire and if the number of
105 seconds is <em>negative</em> a Refresh header.</p>
106 </dd>
107 <dt><strong><a name="rrd_include_filename" class="item">RRD::INCLUDE <em>filename</em></a></strong></dt>
109 <dd>
110 <p>Include the contents of the specified file into the page returned from the cgi.</p>
111 </dd>
112 <dt><strong><a name="rrd_setenv_variable_value" class="item">RRD::SETENV <em>variable</em> <em>value</em></a></strong></dt>
114 <dd>
115 <p>If you want to present your graphs in another time zone than your own, you
116 could use</p>
117 <pre>
118  &lt;RRD::SETENV TZ UTC&gt;</pre>
119 <p>to make sure everything is presented in Universal Time. Note that the
120 values permitted to TZ depend on your OS.</p>
121 </dd>
122 <dt><strong><a name="rrd_setvar_variable_value" class="item">RRD::SETVAR <em>variable</em> <em>value</em></a></strong></dt>
124 <dd>
125 <p>Analog to SETENV but for local variables.</p>
126 </dd>
127 <dt><strong><a name="rrd_getvar_variable" class="item">RRD::GETVAR <em>variable</em></a></strong></dt>
129 <dd>
130 <p>Analog to GETENV but for local variables.</p>
131 </dd>
132 <dt><strong><a name="rrd_time_last_rrd_file_strftime_format" class="item">RRD::TIME::LAST <em>rrd-file</em> <em>strftime-format</em></a></strong></dt>
134 <dd>
135 <p>This gets replaced by the last modification time of the selected RRD. The
136 time is <em>strftime</em>-formatted with the string specified in the second argument.</p>
137 </dd>
138 <dt><strong><a name="rrd_time_now_strftime_format" class="item">RRD::TIME::NOW <em>strftime-format</em></a></strong></dt>
140 <dd>
141 <p>This gets replaced by the current time of day. The time is
142 <em>strftime</em>-formatted with the string specified in the argument.</p>
143 <p>Note that if you return : (colons) from your strftime format you may
144 have to escape them using \ if the time is to be used as an argument
145 to a GRAPH command.</p>
146 </dd>
147 <dt><strong><a name="rrd_time_strftime_start_end_start_spec_end_spec_strftime_format" class="item">RRD::TIME::STRFTIME <em>START|END</em> <em>start-spec</em> <em>end-spec</em> <em>strftime-format</em></a></strong></dt>
149 <dd>
150 <p>This gets replaced by a strftime-formatted time using the format
151 <em>strftime-format</em> on either <em>start-spec</em> or <em>end-spec</em> depending on
152 whether <em>START</em> or <em>END</em> is specified.  Both <em>start-spec</em> and <em>end-spec</em>
153 must be supplied as either could be relative to the other.  This is intended
154 to allow pretty titles on graphs with times that are easier for non RRDtool
155 folks to figure out than &quot;-2weeks&quot;.</p>
156 <p>Note that again, if you return : (colon) from your strftime format,
157 you may have to escape them using \ if the time is to be used as an
158 argument to a GRAPH command.</p>
159 </dd>
160 <dt><strong><a name="rrd_graph_rrdgraph_arguments" class="item">RRD::GRAPH <em>rrdgraph arguments</em></a></strong></dt>
162 <dd>
163 <p>This tag creates the RRD graph defined by its argument and then is
164 replaced by an appropriate &lt;IMG ... &gt; tag referring to the graph.
165 The <strong>--lazy</strong> option in RRD graph can be used to make sure that graphs
166 are only regenerated when they are out of date. The arguments
167 to the <strong>RRD::GRAPH</strong> tag work as described in the <strong>rrdgraph</strong> manual page.</p>
168 <p>Use the <strong>--lazy</strong> option in your RRD::GRAPH tags, to reduce the load
169 on your server. This option makes sure that graphs are only regenerated when
170 the old ones are out of date.</p>
171 <p>If you do not specify your own <strong>--imginfo</strong> format, the following will
172 be used:</p>
173 <pre>
174  &lt;IMG SRC=&quot;%s&quot; WIDTH=&quot;%lu&quot; HEIGHT=&quot;%lu&quot;&gt;</pre>
175 <p>Note that %s stands for the filename part of the graph generated, all
176 directories given in the PNG file argument will get dropped.</p>
177 </dd>
178 <dt><strong><a name="rrd_print_number" class="item">RRD::PRINT <em>number</em></a></strong></dt>
180 <dd>
181 <p>If the preceding  <strong>RRD::GRAPH</strong> tag contained and <strong>PRINT</strong> arguments,
182 then you can access their output with this tag. The <em>number</em> argument refers to the
183 number of the <strong>PRINT</strong> argument. This first <strong>PRINT</strong> has <em>number</em> 0.</p>
184 </dd>
185 <dt><strong><a name="rrd_internal_var" class="item">RRD::INTERNAL &lt;var&gt;</a></strong></dt>
187 <dd>
188 <p>This tag gets replaced by an internal var. Currently these vars are known:
189 VERSION, COMPILETIME.
190 These vars represent the compiled-in values.</p>
191 </dd>
192 </dl>
193 <p>
194 </p>
195 <hr />
196 <h1><a name="example_1">EXAMPLE 1</a></h1>
197 <p>The example below creates a web pages with a single RRD graph.</p>
198 <pre>
199  #!/usr/local/bin/rrdcgi
200  &lt;HTML&gt;
201  &lt;HEAD&gt;&lt;TITLE&gt;RRDCGI Demo&lt;/TITLE&gt;&lt;/HEAD&gt;
202  &lt;BODY&gt;
203  &lt;H1&gt;RRDCGI Example Page&lt;/H1&gt;
204  &lt;P&gt;
205  &lt;RRD::GRAPH demo.png --lazy --title=&quot;Temperatures&quot;
206           DEF:cel=demo.rrd:exhaust:AVERAGE
207           LINE2:cel#00a000:&quot;D. Celsius&quot;&gt;</pre>
208 <pre>
209  &lt;/P&gt;
210  &lt;/BODY&gt;
211  &lt;/HTML&gt;</pre>
212 <p>
213 </p>
214 <hr />
215 <h1><a name="example_2">EXAMPLE 2</a></h1>
216 <p>This script is slightly more elaborate, it allows you to run it from
217 a form which sets RRD_NAME. RRD_NAME is then used to select which RRD
218 you want to use as source for your graph.</p>
219 <pre>
220  #!/usr/local/bin/rrdcgi
221  &lt;HTML&gt;
222  &lt;HEAD&gt;&lt;TITLE&gt;RRDCGI Demo&lt;/TITLE&gt;&lt;/HEAD&gt;
223  &lt;BODY&gt;
224  &lt;H1&gt;RRDCGI Example Page for &lt;RRD::CV RRD_NAME&gt;&lt;/H1&gt;
225  &lt;H2&gt;Selection&lt;/H2&gt;
226  &lt;FORM&gt;&lt;INPUT NAME=RRD_NAME TYPE=RADIO VALUE=roomA&gt; Room A,
227        &lt;INPUT NAME=RRD_NAME TYPE=RADIO VALUE=roomB&gt; Room B.
228        &lt;INPUT TYPE=SUBMIT&gt;&lt;/FORM&gt;
229  &lt;H2&gt;Graph&lt;/H2&gt;
230  &lt;P&gt;
231  &lt;RRD::GRAPH &lt;RRD::CV::PATH RRD_NAME&gt;.png --lazy
232           --title &quot;Temperatures for &quot;&lt;RRD::CV::QUOTE RRD_NAME&gt;
233           DEF:cel=&lt;RRD::CV::PATH RRD_NAME&gt;.rrd:exhaust:AVERAGE
234           LINE2:cel#00a000:&quot;D. Celsius&quot;&gt;</pre>
235 <pre>
236  &lt;/P&gt;
237  &lt;/BODY&gt;
238  &lt;/HTML&gt;</pre>
239 <p>
240 </p>
241 <hr />
242 <h1><a name="example_3">EXAMPLE 3</a></h1>
243 <p>This example shows how to handle the case where the RRD, graphs and
244 cgi-bins are separate directories</p>
245 <pre>
246  #!/.../bin/rrdcgi
247  &lt;HTML&gt;
248  &lt;HEAD&gt;&lt;TITLE&gt;RRDCGI Demo&lt;/TITLE&gt;&lt;/HEAD&gt;
249  &lt;BODY&gt;
250  &lt;H1&gt;RRDCGI test Page&lt;/H1&gt;
251  &lt;RRD::GRAPH
252   /.../web/pngs/testhvt.png
253   --imginfo '&lt;IMG SRC=/.../pngs/%s WIDTH=%lu HEIGHT=%lu &gt;'
254   --lazy --start -1d --end now
255   DEF:http_src=/.../rrds/test.rrd:http_src:AVERAGE
256   AREA:http_src#00ff00:http_src
257  &gt;
258  &lt;/BODY&gt;
259  &lt;/HTML&gt;</pre>
260 <p>Note 1: Replace /.../ with the relevant directories</p>
261 <p>Note 2: The SRC=/.../pngs should be paths from the view of the
262 webserver/browser</p>
263 <p>
264 </p>
265 <hr />
266 <h1><a name="author">AUTHOR</a></h1>
267 <p>Tobias Oetiker &lt;<a href="mailto:tobi@oetiker.ch">tobi@oetiker.ch</a>&gt;</p>
269 </body>
271 </html>