Code

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