Code

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