Code

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