Code

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