Code

Imported upstream SVN snapshot 1.4~rc2+20090928.
[pkg-rrdtool.git] / doc / rrdfetch.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>rrdfetch</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="#resolution_interval">RESOLUTION INTERVAL</a></li>
26                 <li><a href="#at_style_time_specification">AT-STYLE TIME SPECIFICATION</a></li>
27                 <li><a href="#time_reference_specification">TIME REFERENCE SPECIFICATION</a></li>
28                 <li><a href="#time_offset_specification">TIME OFFSET SPECIFICATION</a></li>
29                 <li><a href="#time_specification_examples">TIME SPECIFICATION EXAMPLES</a></li>
30         </ul>
32         <li><a href="#environment_variables">ENVIRONMENT VARIABLES</a></li>
33         <li><a href="#author">AUTHOR</a></li>
34 </ul>
36 -->
39 </div>
40 <!-- INDEX END -->
42 <p>
43 </p>
44 <h1><a name="name">NAME</a></h1>
45 <p>rrdfetch - Fetch data from an RRD.</p>
46 <p>
47 </p>
48 <hr />
49 <h1><a name="synopsis">SYNOPSIS</a></h1>
50 <p><strong>rrdtool</strong> <strong>fetch</strong> <em>filename</em> <em>CF</em>
51 [<strong>--resolution</strong>|<strong>-r</strong>&nbsp;<em>resolution</em>]
52 [<strong>--start</strong>|<strong>-s</strong>&nbsp;<em>start</em>]
53 [<strong>--end</strong>|<strong>-e</strong>&nbsp;<em>end</em>]
54 [<strong>--daemon</strong>&nbsp;<em>address</em>]</p>
55 <p>
56 </p>
57 <hr />
58 <h1><a name="description">DESCRIPTION</a></h1>
59 <p>The <strong>fetch</strong> function is normally used internally by the graph
60 function to get data from <strong>RRD</strong>s. <strong>fetch</strong> will analyze the <strong>RRD</strong>
61 and try to retrieve the data in the resolution requested.
62 The data fetched is printed to stdout. <em>*UNKNOWN*</em> data is often
63 represented by the string &quot;NaN&quot; depending on your OS's printf
64 function.</p>
65 <dl>
66 <dt><strong><a name="filename" class="item"><em>filename</em></a></strong></dt>
68 <dd>
69 <p>the name of the <strong>RRD</strong> you want to fetch the data from.</p>
70 </dd>
71 <dt><strong><a name="cf" class="item"><em>CF</em></a></strong></dt>
73 <dd>
74 <p>the consolidation function that is applied to the data you
75 want to fetch (AVERAGE,MIN,MAX,LAST)</p>
76 </dd>
77 <dt><strong><a name="resolution" class="item"><strong>--resolution</strong>|<strong>-r</strong> <em>resolution</em> (default is the highest resolution)</a></strong></dt>
79 <dd>
80 <p>the interval you want the values to have (seconds per
81 value). <strong>rrdfetch</strong> will try to match your request, but it will return
82 data even if no absolute match is possible. <strong>NB.</strong> See note below.</p>
83 </dd>
84 <dt><strong><a name="start" class="item"><strong>--start</strong>|<strong>-s</strong> <em>start</em> (default end-1day)</a></strong></dt>
86 <dd>
87 <p>start of the time series. A time in seconds since epoch (1970-01-01)
88 is required. Negative numbers are relative to the current time. By default,
89 one day worth of data will be fetched. See also AT-STYLE TIME SPECIFICATION
90 section for a detailed explanation on  ways to specify the start time.</p>
91 </dd>
92 <dt><strong><a name="end" class="item"><strong>--end</strong>|<strong>-e</strong> <em>end</em> (default now)</a></strong></dt>
94 <dd>
95 <p>the end of the time series in seconds since epoch. See also AT-STYLE
96 TIME SPECIFICATION section for a detailed explanation of how to
97 specify the end time.</p>
98 </dd>
99 <dt><strong><a name="daemon_address" class="item"><strong>--daemon</strong> <em>address</em></a></strong></dt>
101 <dd>
102 <p>Address of the <a href="././rrdcached.html">the rrdcached manpage</a> daemon. If specified, a <code>flush</code> command is sent
103 to the server before reading the RRD files. This allows <strong>rrdtool</strong> to return
104 fresh data even if the daemon is configured to cache values for a long time.
105 For a list of accepted formats, see the <strong>-l</strong> option in the <a href="././rrdcached.html">the rrdcached manpage</a> manual.</p>
106 <pre>
107  rrdtool fetch --daemon unix:/var/run/rrdcached.sock /var/lib/rrd/foo.rrd AVERAGE</pre>
108 </dd>
109 </dl>
110 <p>
111 </p>
112 <h2><a name="resolution_interval">RESOLUTION INTERVAL</a></h2>
113 <p>In order to get RRDtool to fetch anything other than the finest resolution RRA
114 <strong>both</strong> the start and end time must be specified on boundaries that are
115 multiples of the desired resolution. Consider the following example:</p>
116 <pre>
117  rrdtool create subdata.rrd -s 10 DS:ds0:GAUGE:300:0:U \
118   RRA:AVERAGE:0.5:30:3600 \
119   RRA:AVERAGE:0.5:90:1200 \
120   RRA:AVERAGE:0.5:360:1200 \
121   RRA:MAX:0.5:360:1200 \
122   RRA:AVERAGE:0.5:8640:600 \
123   RRA:MAX:0.5:8640:600</pre>
124 <p>This RRD collects data every 10 seconds and stores its averages over 5
125 minutes, 15 minutes, 1 hour, and 1 day, as well as the maxima for 1 hour
126 and 1 day.</p>
127 <p>Consider now that you want to fetch the 15 minute average data for the
128 last hour.  You might try</p>
129 <pre>
130  rrdtool fetch subdata.rrd AVERAGE -r 900 -s -1h</pre>
131 <p>However, this will almost always result in a time series that is
132 <strong>NOT</strong> in the 15 minute RRA. Therefore, the highest resolution RRA,
133 i.e. 5 minute averages, will be chosen which in this case is not
134 what you want.</p>
135 <p>Hence, make sure that</p>
136 <ol>
137 <li>
138 <p>both start and end time are a multiple of 900</p>
139 </li>
140 <li>
141 <p>both start and end time are within the desired RRA</p>
142 </li>
143 </ol>
144 <p>So, if time now is called &quot;t&quot;, do</p>
145 <pre>
146  end time == int(t/900)*900,
147  start time == end time - 1hour,
148  resolution == 900.</pre>
149 <p>Using the bash shell, this could look be:</p>
150 <pre>
151  TIME=$(date +%s)
152  RRDRES=900
153  rrdtool fetch subdata.rrd AVERAGE -r $RRDRES \
154     -e $(($TIME/$RRDRES*$RRDRES)) -s e-1h</pre>
155 <p>Or in Perl:</p>
156 <pre>
157  perl -e '$ctime = time; $rrdres = 900; \
158           system &quot;rrdtool fetch subdata.rrd AVERAGE \
159                   -r $rrdres -e @{[int($ctime/$rrdres)*$rrdres]} -s e-1h&quot;'</pre>
160 <p>
161 </p>
162 <h2><a name="at_style_time_specification">AT-STYLE TIME SPECIFICATION</a></h2>
163 <p>Apart from the traditional <em>Seconds since epoch</em>, RRDtool does also
164 understand at-style time specification. The specification is called
165 &quot;at-style&quot; after the Unix command <code>at(1)</code> that has moderately complex
166 ways to specify time to run your job at a certain date and time. The
167 at-style specification consists of two parts: the <strong>TIME REFERENCE</strong>
168 specification and the <strong>TIME OFFSET</strong> specification.</p>
169 <p>
170 </p>
171 <h2><a name="time_reference_specification">TIME REFERENCE SPECIFICATION</a></h2>
172 <p>The time reference specification is used, well, to establish a reference
173 moment in time (to which the time offset is then applied to). When present,
174 it should come first, when omitted, it defaults to <strong>now</strong>. On its own part,
175 time reference consists of a <em>time-of-day</em> reference (which should come
176 first, if present) and a <em>day</em> reference.</p>
177 <p>The <em>time-of-day</em> can be specified as <strong>HH:MM</strong>, <strong>HH.MM</strong>,
178 or just <strong>HH</strong>. You can suffix it with <strong>am</strong> or <strong>pm</strong> or use
179 24-hours clock. Some special times of day are understood as well,
180 including <strong>midnight</strong> (00:00), <strong>noon</strong> (12:00) and British
181 <strong>teatime</strong> (16:00).</p>
182 <p>The <em>day</em> can be specified as <em>month-name</em> <em>day-of-the-month</em> and
183 optional a 2- or 4-digit <em>year</em> number (e.g. March 8 1999). Alternatively,
184 you can use <em>day-of-week-name</em> (e.g. Monday), or one of the words:
185 <strong>yesterday</strong>, <strong>today</strong>, <strong>tomorrow</strong>. You can also specify the <em>day</em> as a
186 full date in several numerical formats, including <strong>MM/DD/[YY]YY</strong>,
187 <strong>DD.MM.[YY]YY</strong>, or <strong>YYYYMMDD</strong>.</p>
188 <p><em>NOTE1</em>: this is different from the original <code>at(1)</code> behavior, where a
189 single-number date is interpreted as MMDD[YY]YY.</p>
190 <p><em>NOTE2</em>: if you specify the <em>day</em> in this way, the <em>time-of-day</em> is
191 REQUIRED as well.</p>
192 <p>Finally, you can use the words <strong>now</strong>, <strong>start</strong>, or <strong>end</strong> as your time
193 reference. <strong>Now</strong> refers to the current moment (and is also the default
194 time reference). <strong>Start</strong> (<strong>end</strong>) can be used to specify a time
195 relative to the start (end) time for those tools that use these
196 categories (<strong>rrdfetch</strong>, <a href="././rrdgraph.html">the rrdgraph manpage</a>).</p>
197 <p>Month and day of the week names can be used in their naturally
198 abbreviated form (e.g., Dec for December, Sun for Sunday, etc.). The
199 words <strong>now</strong>, <strong>start</strong>, <strong>end</strong> can be abbreviated as <strong>n</strong>, <strong>s</strong>, <strong>e</strong>.</p>
200 <p>
201 </p>
202 <h2><a name="time_offset_specification">TIME OFFSET SPECIFICATION</a></h2>
203 <p>The time offset specification is used to add/subtract certain time
204 intervals to/from the time reference moment. It consists of a <em>sign</em>
205 (<strong>+</strong>&nbsp;or&nbsp;<strong>-</strong>) and an <em>amount</em>. The following time units can be
206 used to specify the <em>amount</em>: <strong>years</strong>, <strong>months</strong>, <strong>weeks</strong>, <strong>days</strong>,
207 <strong>hours</strong>, <strong>minutes</strong>, or <strong>seconds</strong>. These units can be used in
208 singular or plural form, and abbreviated naturally or to a single
209 letter (e.g. +3days, -1wk, -3y). Several time units can be combined
210 (e.g., -5mon1w2d) or concatenated (e.g., -5h45min = -5h-45min =
211 -6h+15min = -7h+1h30m-15min, etc.)</p>
212 <p><em>NOTE3</em>: If you specify time offset in days, weeks, months, or years,
213 you will end with the time offset that may vary depending on your time
214 reference, because all those time units have no single well defined
215 time interval value (1&nbsp;year contains either 365 or 366 days, 1&nbsp;month
216 is 28 to 31 days long, and even 1&nbsp;day may be not equal to 24 hours
217 twice a year, when DST-related clock adjustments take place).
218 To cope with this, when you use days, weeks, months, or years
219 as your time offset units your time reference date is adjusted
220 accordingly without too much further effort to ensure anything
221 about it (in the hope that <code>mktime(3)</code> will take care of this later).
222 This may lead to some surprising (or even invalid!) results,
223 e.g. 'May&nbsp;31&nbsp;-1month' = 'Apr&nbsp;31' (meaningless) = 'May&nbsp;1'
224 (after <code>mktime(3)</code> normalization); in the EET timezone
225 '3:30am Mar 29 1999 -1 day' yields '3:30am Mar 28 1999' (Sunday)
226 which is an invalid time/date combination (because of 3am -&gt; 4am DST
227 forward clock adjustment, see the below example).</p>
228 <p>In contrast, hours, minutes, and seconds are well defined time
229 intervals, and these are guaranteed to always produce time offsets
230 exactly as specified (e.g. for EET timezone, '8:00&nbsp;Mar&nbsp;27&nbsp;1999&nbsp;+2
231 days' = '8:00&nbsp;Mar&nbsp;29&nbsp;1999', but since there is 1-hour DST forward
232 clock adjustment that occurs around 3:00&nbsp;Mar&nbsp;28&nbsp;1999, the actual
233 time interval between 8:00&nbsp;Mar&nbsp;27&nbsp;1999 and 8:00&nbsp;Mar&nbsp;29&nbsp;1999
234 equals 47 hours; on the other hand, '8:00&nbsp;Mar&nbsp;27&nbsp;1999&nbsp;+48&nbsp;hours' =
235 '9:00&nbsp;Mar&nbsp;29&nbsp;1999', as expected)</p>
236 <p><em>NOTE4</em>: The single-letter abbreviation for both <strong>months</strong> and <strong>minutes</strong>
237 is <strong>m</strong>. To disambiguate them, the parser tries to read your mind&nbsp;:)
238 by applying the following two heuristics:</p>
239 <ol>
240 <li>
241 <p>If <strong>m</strong> is used in context of (i.e. right after the) years,
242 months, weeks, or days it is assumed to mean <strong>months</strong>, while
243 in the context of hours, minutes, and seconds it means minutes.
244 (e.g., in -1y6m or +3w1m <strong>m</strong> is interpreted as <strong>months</strong>, while in
245 -3h20m or +5s2m <strong>m</strong> the parser decides for <strong>minutes</strong>).</p>
246 </li>
247 <li>
248 <p>Out of context (i.e. right after the <strong>+</strong> or <strong>-</strong> sign) the
249 meaning of <strong>m</strong> is guessed from the number it directly follows.
250 Currently, if the number's absolute value is below 25 it is assumed
251 that <strong>m</strong> means <strong>months</strong>, otherwise it is treated as <strong>minutes</strong>.
252 (e.g., -25m == -25 minutes, while +24m == +24 months)</p>
253 </li>
254 </ol>
255 <p><em>Final NOTES</em>: Time specification is case-insensitive.
256 Whitespace can be inserted freely or omitted altogether.
257 There are, however, cases when whitespace is required
258 (e.g., 'midnight&nbsp;Thu'). In this case you should either quote the
259 whole phrase to prevent it from being taken apart by your shell or use
260 '_' (underscore) or ',' (comma) which also count as whitespace
261 (e.g., midnight_Thu or midnight,Thu).</p>
262 <p>
263 </p>
264 <h2><a name="time_specification_examples">TIME SPECIFICATION EXAMPLES</a></h2>
265 <p><em>Oct 12</em> -- October 12 this year</p>
266 <p><em>-1month</em> or <em>-1m</em> -- current time of day, only a month before
267 (may yield surprises, see NOTE3 above).</p>
268 <p><em>noon yesterday -3hours</em> -- yesterday morning; can also be specified
269 as <em>9am-1day</em>.</p>
270 <p><em>23:59 31.12.1999</em> -- 1 minute to the year 2000.</p>
271 <p><em>12/31/99 11:59pm</em> -- 1 minute to the year 2000 for imperialists.</p>
272 <p><em>12am 01/01/01</em> -- start of the new millennium</p>
273 <p><em>end-3weeks</em> or <em>e-3w</em> -- 3 weeks before end time
274 (may be used as start time specification).</p>
275 <p><em>start+6hours</em> or <em>s+6h</em> -- 6 hours after start time
276 (may be used as end time specification).</p>
277 <p><em>931225537</em> -- 18:45  July 5th, 1999
278 (yes, seconds since 1970 are valid as well).</p>
279 <p><em>19970703 12:45</em> -- 12:45  July 3th, 1997
280 (my favorite, and its even got an ISO number (8601)).</p>
281 <p>
282 </p>
283 <hr />
284 <h1><a name="environment_variables">ENVIRONMENT VARIABLES</a></h1>
285 <p>The following environment variables may be used to change the behavior of
286 <code>rrdtoolfetch</code>:</p>
287 <dl>
288 <dt><strong><a name="rrdcached_address" class="item"><strong>RRDCACHED_ADDRESS</strong></a></strong></dt>
290 <dd>
291 <p>If this environment variable is set it will have the same effect as specifying
292 the <code>--daemon</code> option on the command line. If both are present, the command
293 line argument takes precedence.</p>
294 </dd>
295 </dl>
296 <p>
297 </p>
298 <hr />
299 <h1><a name="author">AUTHOR</a></h1>
300 <p>Tobias Oetiker &lt;<a href="mailto:tobi@oetiker.ch">tobi@oetiker.ch</a>&gt;</p>
302 </body>
304 </html>