Code

7ae3bf180a14be2317a2e64a201a5e753ad7d71e
[pkg-rrdtool.git] / doc / rrdtutorial.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>rrdtutorial</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="#description">DESCRIPTION</a></li>
20         <li><a href="#tutorial">TUTORIAL</a></li>
21         <ul>
23                 <li><a href="#important">Important</a></li>
24                 <li><a href="#what_is_rrdtool">What is RRDtool?</a></li>
25                 <li><a href="#what_data_can_be_put_into_an_rrd">What data can be put into an RRD?</a></li>
26                 <li><a href="#what_can_i_do_with_this_tool">What can I do with this tool?</a></li>
27                 <li><a href="#what_if_i_still_have_problems_after_reading_this_document">What if I still have problems after reading this document?</a></li>
28                 <li><a href="#how_will_you_help_me">How will you help me?</a></li>
29                 <li><a href="#your_first_round_robin_database">Your first Round Robin Database</a></li>
30                 <li><a href="#what_has_been_created">What has been created?</a></li>
31                 <li><a href="#time_to_create_some_graphics">Time to create some graphics</a></li>
32                 <li><a href="#graphics_with_some_math">Graphics with some math</a></li>
33                 <li><a href="#graphics_magic">Graphics Magic</a></li>
34                 <li><a href="#updates_in_reality">Updates in Reality</a></li>
35                 <li><a href="#some_words_on_snmp">Some words on SNMP</a></li>
36                 <li><a href="#a_real_world_example">A Real World Example</a></li>
37                 <li><a href="#consolidation_functions">Consolidation Functions</a></li>
38                 <li><a href="#let_s_review_what_you_now_should_know">Let's review what you now should know</a></li>
39                 <li><a href="#data_source_types">Data Source Types</a></li>
40                 <li><a href="#rrdtool_under_the_microscope">RRDtool under the Microscope</a></li>
41                 <li><a href="#counter_wraps">Counter Wraps</a></li>
42                 <li><a href="#data_resampling">Data Resampling</a></li>
43         </ul>
45         <li><a href="#wrapup">WRAPUP</a></li>
46         <li><a href="#mailinglist">MAILINGLIST</a></li>
47         <li><a href="#see_also">SEE ALSO</a></li>
48         <li><a href="#author">AUTHOR</a></li>
49 </ul>
50 -->
51 <!-- INDEX END -->
53 <p>
54 </p>
55 <h1><a name="name">NAME</a></h1>
56 <p>rrdtutorial - Alex van den Bogaerdt's RRDtool tutorial</p>
57 <p>
58 </p>
59 <hr />
60 <h1><a name="description">DESCRIPTION</a></h1>
61 <p>RRDtool is written by Tobias Oetiker &lt;<a href="mailto:tobi@oetiker.ch">tobi@oetiker.ch</a>&gt; with
62 contributions from many people all around the world. This document is
63 written by Alex van den Bogaerdt &lt;<a href="mailto:alex@ergens.op.het.net">alex@ergens.op.het.net</a>&gt; to help you
64 understand what RRDtool is and what it can do for you.</p>
65 <p>The documentation provided with RRDtool can be too technical for some
66 people. This tutorial is here to help you understand the basics of
67 RRDtool. It should prepare you to read the documentation yourself.
68 It also explains the general things about statistics with a focus on
69 networking.</p>
70 <p>
71 </p>
72 <hr />
73 <h1><a name="tutorial">TUTORIAL</a></h1>
74 <p>
75 </p>
76 <h2><a name="important">Important</a></h2>
77 <p>Please don't skip ahead in this document!  The first part of this
78 document explains the basics and may be boring.  But if you don't
79 understand the basics, the examples will not be as meaningful to you.</p>
80 <p>
81 </p>
82 <h2><a name="what_is_rrdtool">What is RRDtool?</a></h2>
83 <p>RRDtool refers to Round Robin Database tool.
84 Round robin is a technique that works with a fixed amount of data, and a
85 pointer to the current element. Think of a circle with some dots plotted
86 on the edge -- these dots are the places where data can be stored. Draw an
87 arrow from the center of the circle to one of the dots -- this is the pointer.
88 When the current data is read or written, the pointer moves to the next
89 element. As we are on a circle there is neither a beginning nor an end, you can
90 go on and on and on. After a while, all the available places will be used and
91 the process automatically reuses old locations. This way, the dataset
92 will not grow in size and therefore requires no maintenance.
93 RRDtool works with with Round Robin Databases (RRDs). It stores and retrieves
94 data from them.</p>
95 <p>
96 </p>
97 <h2><a name="what_data_can_be_put_into_an_rrd">What data can be put into an RRD?</a></h2>
98 <p>You name it, it will probably fit as long as it is some sort of time-series
99 data. This means you have to be able to measure some value at several points in time and
100 provide this information to RRDtool. If you can do this, RRDtool will be
101 able to store it. The values must be numerical but don't have to be
102 integers, as is the case with MRTG (the next section will give more details
103 on this more specialized application).</p>
104 <p>Many examples below talk about SNMP which is an acronym for Simple Network
105 Management Protocol. ``Simple'' refers to the protocol -- it does not
106 mean it is simple to manage or monitor a network. After working your
107 way through this document, you should know enough to be able to
108 understand what people are talking about. For now, just realize that
109 SNMP can be used to query devices for the values of counters they keep. It
110 is the value from those counters that we want to store in the RRD.</p>
111 <p>
112 </p>
113 <h2><a name="what_can_i_do_with_this_tool">What can I do with this tool?</a></h2>
114 <p>RRDtool originated from MRTG (Multi Router Traffic Grapher). MRTG
115 started as a tiny little script for graphing the use of a university's
116 connection to the Internet. MRTG was later (ab-)used as a tool for
117 graphing other data sources including temperature, speed, voltage,
118 number of printouts and the like.</p>
119 <p>Most likely you will start to use RRDtool to store and process data
120 collected via SNMP. The data will most likely be bytes (or bits)
121 transfered from and to a network or a computer.  But it can also be
122 used to display tidal waves, solar radiation, power consumption,
123 number of visitors at an exhibition, noise levels near an airport,
124 temperature on your favorite holiday location, temperature in the
125 fridge and whatever you imagination can come up with.</p>
126 <p>You only need a sensor to measure the data and be able to feed the
127 numbers into RRDtool. RRDtool then lets you create a database, store
128 data in it, retrieve that data and create graphs in PNG format for
129 display on a web browser. Those PNG images are dependent on the data
130 you collected and could be, for instance, an overview of the average
131 network usage, or the peaks that occurred.</p>
132 <p>
133 </p>
134 <h2><a name="what_if_i_still_have_problems_after_reading_this_document">What if I still have problems after reading this document?</a></h2>
135 <p>First of all: read it again! You may have missed something.
136 If you are unable to compile the sources and you have a fairly common
137 OS, it will probably not be the fault of RRDtool. There may be pre-compiled
138 versions around on the Internet. If they come from trusted sources, get
139 one of those.</p>
140 <p>If on the other hand the program works but does not give you the
141 expected results, it will be a problem with configuring it. Review
142 your configuration and compare it with the examples that follow.</p>
143 <p>There is a mailing list and an archive of it. Read the list for a few
144 weeks and search the archive. It is considered rude to just ask
145 a question without searching the archives: your problem may already have been
146 solved for somebody else!  This is true for most, if not all, mailing lists
147 and not only for this particular one. Look in the documentation that
148 came with RRDtool for the location and usage of the list.</p>
149 <p>I suggest you take a moment to subscribe to the mailing list right now
150 by sending an email to &lt;<a href="mailto:rrd-users-request@lists.oetiker.ch">rrd-users-request@lists.oetiker.ch</a>&gt; with a
151 subject of ``subscribe''. If you ever want to leave this list, just write
152 an email to the same address but now with a subject of ``unsubscribe''.</p>
153 <p>
154 </p>
155 <h2><a name="how_will_you_help_me">How will you help me?</a></h2>
156 <p>By giving you some detailed descriptions with detailed examples.
157 I assume that following the instructions in the order presented
158 will give you enough knowledge of RRDtool to experiment for yourself.
159 If it doesn't work the first time, don't give up. Reread the stuff that
160 you did understand, you may have missed something.</p>
161 <p>By following the examples you get some hands-on experience and, even
162 more important, some background information of how it works.</p>
163 <p>You will need to know something about hexadecimal numbers. If you don't
164 then start with reading bin_dec_hex tutorial before you continue here.</p>
165 <p>
166 </p>
167 <h2><a name="your_first_round_robin_database">Your first Round Robin Database</a></h2>
168 <p>In my opinion the best way to learn something is to actually do it.
169 Why not start right now?  We will create a database, put some values
170 in it and extract this data again.  Your output should be the same
171 as the output that is included in this document.</p>
172 <p>We will start with some easy stuff and compare a car with a router,
173 or compare kilometers (miles if you wish) with bits and bytes. It's
174 all the same: some number over some time.</p>
175 <p>Assume we have a device that transfers bytes to and from the Internet.
176 This device keeps a counter that starts at zero when it is turned on,
177 increasing with every byte that is transfered. This counter will probably have
178 a maximum value. If this value is reached and an extra byte is counted,
179 the counter starts over at zero. This is the same as many counters
180 in the world such as the mileage counter in a car.</p>
181 <p>Most discussions about networking talk about bits per second so lets
182 get used to that right away. Assume a byte is eight bits and start to
183 think in bits not bytes. The counter, however, still counts bytes!
184 In the SNMP world most of the counters are 32 bits. That means they are
185 counting from 0 to 4'294'967'295. We will use these values in the examples.
186 The device, when asked, returns the current value of the counter. We
187 know the time that has passes since we last asked so we now know how
188 many bytes have been transfered ***on average*** per second. This is
189 not very hard to calculate. First in words, then in calculations:</p>
190 <ol>
191 <li>
192 <p>Take the current counter, subtract the previous value from it.</p>
193 </li>
194 <li>
195 <p>Do the same with the current time and the previous time (in seconds).</p>
196 </li>
197 <li>
198 <p>Divide the outcome of (1) by the outcome of (2), the result is
199 the amount of bytes per second. Multiply by eight to get the
200 number of bits per second (bps).</p>
201 </li>
202 </ol>
203 <pre>
204   bps = (counter_now - counter_before) / (time_now - time_before) * 8</pre>
205 <p>For some people it may help to translate this to an automobile example.
206 Do not try this example, and if you do, don't blame me for the results!</p>
207 <p>People who are not used to think in kilometers per hour can translate
208 most into miles per hour by dividing km by 1.6 (close enough).
209 I will use the following abbreviations:</p>
210 <pre>
211  M:    meter
212  KM:   kilometer (= 1'000 meters).
213  H:    hour
214  S:    second
215  KM/H: kilometers per hour
216  M/S:  meters per second</pre>
217 <p>You are driving a car. At 12:05 you read the counter in the dashboard
218 and it tells you that the car has moved 12'345 KM until that moment.
219 At 12:10 you look again, it reads 12'357 KM. This means you have
220 traveled 12 KM in five minutes. A scientist would translate that
221 into meters per second and this makes a nice comparison toward the
222 problem of (bytes per five minutes) versus (bits per second).</p>
223 <p>We traveled 12 kilometers which is 12'000 meters. We did that in five
224 minutes or 300 seconds. Our speed is 12'000M / 300S or 40 M/S.</p>
225 <p>We could also calculate the speed in KM/H: 12 times 5 minutes
226 is an hour, so we have to multiply 12 KM by 12 to get 144 KM/H.
227 For our native English speaking friends: that's 90 MPH so don't
228 try this example at home or where I live :)</p>
229 <p>Remember: these numbers are averages only.  There is no way to figure out
230 from the numbers, if you drove at a constant speed.  There is an example
231 later on in this tutorial that explains this.</p>
232 <p>I hope you understand that there is no difference in calculating M/S or
233 bps; only the way we collect the data is different. Even the K from kilo
234 is the same as in networking terms k also means 1'000.</p>
235 <p>We will now create a database where we can keep all these interesting
236 numbers. The method used to start the program may differ slightly from
237 OS to OS, but I assume you can figure it out if it works different on
238 your's. Make sure you do not overwrite any file on your system when
239 executing the following command and type the whole line as one long
240 line (I had to split it for readability)
241 and skip all of the '\' characters.</p>
242 <pre>
243    rrdtool create test.rrd             \
244             --start 920804400          \
245             DS:speed:COUNTER:600:U:U   \
246             RRA:AVERAGE:0.5:1:24       \
247             RRA:AVERAGE:0.5:6:10</pre>
248 <p>(So enter: <code>rrdtool create test.rrd --start 920804400 DS ...</code>)</p>
249 <p>
250 </p>
251 <h2><a name="what_has_been_created">What has been created?</a></h2>
252 <p>We created the round robin database called test (test.rrd) which starts at
253 noon the day I started writing this document, 7th of March, 1999 (this date
254 translates to 920'804'400 seconds as explained below). Our database holds
255 one data source (DS) named ``speed'' that represents a counter. This counter
256 is read every five minutes (this is the default therefore you don't have to
257 put <code>--step=300</code>).  In the same database two round robin archives (RRAs)
258 are kept, one averages the data every time it is read (e.g., there's nothing
259 to average) and keeps 24 samples (24 times 5 minutes is 2 hours). The other
260 averages 6 values (half hour) and contains 10 such averages (e.g. 5 hours).</p>
261 <p>RRDtool works with special time stamps coming from the UNIX world.
262 This time stamp is the number of seconds that passed since January
263 1st 1970 UTC.  The time stamp value is translated into local time and
264 it will therefore look different for different time zones.</p>
265 <p>Chances are that you are not in the same part of the world as I am.
266 This means your time zone is different. In all examples where I talk
267 about time, the hours may be wrong for you. This has little effect on
268 the results of the examples, just correct the hours while reading.
269 As an example: where I will see ``12:05'' the UK folks will see ``11:05''.</p>
270 <p>We now have to fill our database with some numbers. We'll pretend to
271 have read the following numbers:</p>
272 <pre>
273  12:05  12345 KM
274  12:10  12357 KM
275  12:15  12363 KM
276  12:20  12363 KM
277  12:25  12363 KM
278  12:30  12373 KM
279  12:35  12383 KM
280  12:40  12393 KM
281  12:45  12399 KM
282  12:50  12405 KM
283  12:55  12411 KM
284  13:00  12415 KM
285  13:05  12420 KM
286  13:10  12422 KM
287  13:15  12423 KM</pre>
288 <p>We fill the database as follows:</p>
289 <pre>
290  rrdtool update test.rrd 920804700:12345 920805000:12357 920805300:12363
291  rrdtool update test.rrd 920805600:12363 920805900:12363 920806200:12373
292  rrdtool update test.rrd 920806500:12383 920806800:12393 920807100:12399
293  rrdtool update test.rrd 920807400:12405 920807700:12411 920808000:12415
294  rrdtool update test.rrd 920808300:12420 920808600:12422 920808900:12423</pre>
295 <p>This reads: update our test database with the following numbers</p>
296 <pre>
297  time 920804700, value 12345
298  time 920805000, value 12357</pre>
299 <p>etcetera.</p>
300 <p>As you can see, it is possible to feed more than one value into the
301 database in one command. I had to stop at three for readability but
302 the real maximum per line is OS dependent.</p>
303 <p>We can now retrieve the data from our database using ``rrdtool fetch'':</p>
304 <pre>
305  rrdtool fetch test.rrd AVERAGE --start 920804400 --end 920809200</pre>
306 <p>It should return the following output:</p>
307 <pre>
308                           speed</pre>
309 <pre>
310  920804700: nan
311  920805000: 4.0000000000e-02
312  920805300: 2.0000000000e-02
313  920805600: 0.0000000000e+00
314  920805900: 0.0000000000e+00
315  920806200: 3.3333333333e-02
316  920806500: 3.3333333333e-02
317  920806800: 3.3333333333e-02
318  920807100: 2.0000000000e-02
319  920807400: 2.0000000000e-02
320  920807700: 2.0000000000e-02
321  920808000: 1.3333333333e-02
322  920808300: 1.6666666667e-02
323  920808600: 6.6666666667e-03
324  920808900: 3.3333333333e-03
325  920809200: nan</pre>
326 <p>If it doesn't, something may be wrong.  Perhaps your OS will print
327 ``NaN'' in a different form. ``NaN'' stands for ``Not A Number''.  If your OS
328 writes ``U'' or ``UNKN'' or something similar that's okay.  If something
329 else is wrong, it will probably be due to an error you made (assuming
330 that my tutorial is correct of course :-). In that case: delete the
331 database and try again.  Sometimes things change.  This example used
332 to provide numbers like ``0.04'' in stead of ``4.00000e-02''.  Those are
333 really the same numbers, just written down differently.  Don't be
334 alarmed if a future version of rrdtool displays a slightly different
335 form of output. The examples in this document are correct for version
336 1.2.0 of RRDtool.</p>
337 <p>The meaning of the above output will become clear below.</p>
338 <p>
339 </p>
340 <h2><a name="time_to_create_some_graphics">Time to create some graphics</a></h2>
341 <p>Try the following command:</p>
342 <pre>
343  rrdtool graph speed.png                                 \
344          --start 920804400 --end 920808000               \
345          DEF:myspeed=test.rrd:speed:AVERAGE              \
346          LINE2:myspeed#FF0000</pre>
347 <p>This will create speed.png which starts at 12:00 and ends at 13:00.
348 There is a definition of a variable called myspeed, using the data from RRA
349 ``speed'' out of database ``test.rrd''. The line drawn is 2 pixels high
350 and represents the variable myspeed. The color is red (specified by
351 its rgb-representation, see below).</p>
352 <p>You'll notice that the start of the graph is not at 12:00 but at 12:05.
353 This is because we have insufficient data to tell the average before
354 that time. This will only happen when you miss some samples, this will
355 not happen a lot, hopefully.</p>
356 <p>If this has worked: congratulations! If not, check what went wrong.</p>
357 <p>The colors are built up from red, green and blue. For each of the
358 components, you specify how much to use in hexadecimal where 00 means
359 not included and FF means fully included.
360 The ``color'' white is a mixture of red, green and blue: FFFFFF
361 The ``color'' black is all colors off: 000000</p>
362 <pre>
363    red     #FF0000
364    green   #00FF00
365    blue    #0000FF
366    magenta #FF00FF     (mixed red with blue)
367    gray    #555555     (one third of all components)</pre>
368 <p>Additionally you can add an alpha channel (transparency).  The default
369 will be ``FF'' which means non-transparent.</p>
370 <p>The PNG you just created can be displayed using your favorite image
371 viewer.  Web browsers will display the PNG via the URL
372 ``file:///the/path/to/speed.png''</p>
373 <p>
374 </p>
375 <h2><a name="graphics_with_some_math">Graphics with some math</a></h2>
376 <p>When looking at the image, you notice that the horizontal axis is labeled
377 12:10, 12:20, 12:30, 12:40 and 12:50. Sometimes a label doesn't fit (12:00
378 and 13:00 would be candidates) so they are skipped.</p>
379 <p>The vertical axis displays the range we entered. We provided
380 kilometers and when divided by 300 seconds, we get very small
381 numbers. To be exact, the first value was 12 (12'357-12'345) and divided
382 by 300 this makes 0.04, which is displayed by RRDtool as ``40 m''
383 meaning ``40/1'000''. The ``m'' (milli) has nothing to do with meters,
384 kilometers or millimeters! RRDtool doesn't know about the physical
385 units of our data, it just works with dimensionless numbers.</p>
386 <p>If we had measured our distances in meters, this would have been
387 (12'357'000-12'345'000)/300 = 12'000/300 = 40.</p>
388 <p>As most people have a better feel for numbers in this range, we'll
389 correct that. We could recreate our database and store the correct
390 data, but there is a better way: we do some calculations while creating
391 the png file!</p>
392 <pre>
393    rrdtool graph speed2.png                           \
394       --start 920804400 --end 920808000               \
395       --vertical-label m/s                            \
396       DEF:myspeed=test.rrd:speed:AVERAGE              \
397       CDEF:realspeed=myspeed,1000,\*                  \
398       LINE2:realspeed#FF0000</pre>
399 <p>Note: Make sure not to forget the backslash \ in front of the
400 multiplication operator * above. The backslash is needed to ``escape''
401 the * as some operating systems might interpret and expand * instead
402 of passing it to the rrdtool command.</p>
403 <p>After viewing this PNG, you notice the ``m'' (milli) has
404 disappeared. This it what the correct result would be. Also, a label
405 has been added to the image.  Apart from the things mentioned above,
406 the PNG should look the same.</p>
407 <p>The calculations are specified in the CDEF part above and are in
408 Reverse Polish Notation (``RPN''). What we requested RRDtool to do is:
409 ``take the data source myspeed and the number 1000; multiply
410 those''. Don't bother with RPN yet, it will be explained later on in
411 more detail. Also, you may want to read my tutorial on CDEFs and Steve
412 Rader's tutorial on RPN. But first finish this tutorial.</p>
413 <p>Hang on! If we can multiply values with 1'000, it should also be possible
414 to display kilometers per hour from the same data!</p>
415 <p>To change a value that is measured in meters per second:</p>
416 <pre>
417  Calculate meters per hour:     value * 3'600
418  Calculate kilometers per hour: value / 1'000
419  Together this makes:           value * (3'600/1'000) or value * 3.6</pre>
420 <p>In our example database we made a mistake and we need to compensate for
421 this by multiplying with 1'000. Applying that correction:</p>
422 <pre>
423  value * 3.6  * 1'000 == value * 3'600</pre>
424 <p>Now let's create this PNG, and add some more magic ...</p>
425 <pre>
426  rrdtool graph speed3.png                             \
427       --start 920804400 --end 920808000               \
428       --vertical-label km/h                           \
429       DEF:myspeed=test.rrd:speed:AVERAGE              \
430       &quot;CDEF:kmh=myspeed,3600,*&quot;                       \
431       CDEF:fast=kmh,100,GT,kmh,0,IF                   \
432       CDEF:good=kmh,100,GT,0,kmh,IF                   \
433       HRULE:100#0000FF:&quot;Maximum allowed&quot;              \
434       AREA:good#00FF00:&quot;Good speed&quot;                   \
435       AREA:fast#FF0000:&quot;Too fast&quot;</pre>
436 <p>Note: here we use another means to escape the * operator by enclosing
437 the whole string in double quotes.</p>
438 <p>This graph looks much better. Speed is shown in KM/H and there is even
439 an extra line with the maximum allowed speed (on the road I travel
440 on). I also changed the colors used to display speed and changed it
441 from a line into an area.</p>
442 <p>The calculations are more complex now. For speed measurements within
443 the speed limit they are:</p>
444 <pre>
445    Check if kmh is greater than 100    ( kmh,100 ) GT
446    If so, return 0, else kmh           ((( kmh,100 ) GT ), 0, kmh) IF</pre>
447 <p>For values above the speed limit:</p>
448 <pre>
449    Check if kmh is greater than 100    ( kmh,100 ) GT
450    If so, return kmh, else return 0    ((( kmh,100) GT ), kmh, 0) IF</pre>
451 <p>
452 </p>
453 <h2><a name="graphics_magic">Graphics Magic</a></h2>
454 <p>I like to believe there are virtually no limits to how RRDtool graph
455 can manipulate data. I will not explain how it works, but look at the
456 following PNG:</p>
457 <pre>
458    rrdtool graph speed4.png                           \
459       --start 920804400 --end 920808000               \
460       --vertical-label km/h                           \
461       DEF:myspeed=test.rrd:speed:AVERAGE              \
462       &quot;CDEF:kmh=myspeed,3600,*&quot;                       \
463       CDEF:fast=kmh,100,GT,100,0,IF                   \
464       CDEF:over=kmh,100,GT,kmh,100,-,0,IF             \
465       CDEF:good=kmh,100,GT,0,kmh,IF                   \
466       HRULE:100#0000FF:&quot;Maximum allowed&quot;              \
467       AREA:good#00FF00:&quot;Good speed&quot;                   \
468       AREA:fast#550000:&quot;Too fast&quot;                     \
469       STACK:over#FF0000:&quot;Over speed&quot;</pre>
470 <p>Let's create a quick and dirty HTML page to view the three PNGs:</p>
471 <pre>
472    &lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Speed&lt;/TITLE&gt;&lt;/HEAD&gt;&lt;BODY&gt;
473    &lt;IMG src=&quot;speed2.png&quot; alt=&quot;Speed in meters per second&quot;&gt;
474    &lt;BR&gt;
475    &lt;IMG src=&quot;speed3.png&quot; alt=&quot;Speed in kilometers per hour&quot;&gt;
476    &lt;BR&gt;
477    &lt;IMG src=&quot;speed4.png&quot; alt=&quot;Traveled too fast?&quot;&gt;
478    &lt;/BODY&gt;&lt;/HTML&gt;</pre>
479 <p>Name the file ``speed.html'' or similar, and look at it in your web browser.</p>
480 <p>Now, all you have to do is measure the values regularly and update the
481 database.  When you want to view the data, recreate the PNGs and make
482 sure to refresh them in your browser. (Note: just clicking reload may
483 not be enough, especially when proxies are involved.  Try shift-reload
484 or ctrl-F5).</p>
485 <p>
486 </p>
487 <h2><a name="updates_in_reality">Updates in Reality</a></h2>
488 <p>We've already used the <code>update</code> command: it took one or more
489 parameters in the form of ``&lt;time&gt;:&lt;value&gt;''. You'll be glad to know
490 that you can specify the current time by filling in a ``N'' as the time.
491 Or you could use the ``time'' function in Perl (the shortest example in
492 this tutorial):</p>
493 <pre>
494    perl -e 'print time, &quot;\n&quot; '</pre>
495 <p>How to run a program on regular intervals is OS specific. But here is
496 an example in pseudo code:</p>
497 <pre>
498    - Get the value and put it in variable &quot;$speed&quot;
499    - rrdtool update speed.rrd N:$speed</pre>
500 <p>(do not try this with our test database, we'll use it in further examples)</p>
501 <p>This is all. Run the above script every five minutes. When you need to know
502 what the graphs look like, run the examples above. You could put them
503 in a script as well. After running that script, view the page
504 index.html we created above.</p>
505 <p>
506 </p>
507 <h2><a name="some_words_on_snmp">Some words on SNMP</a></h2>
508 <p>I can imagine very few people that will be able to get real data from
509 their car every five minutes. All other people will have to settle for
510 some other kind of counter. You could measure the number of pages
511 printed by a printer, for example, the cups of coffee made by the
512 coffee machine, a device that counts the electricity used,
513 whatever. Any incrementing counter can be monitored and graphed using
514 the stuff you learned so far. Later on we will also be able to monitor
515 other types of values like temperature.</p>
516 <p>Most (?) people interested in RRDtool will use the counter that keeps track
517 of octets (bytes) transfered by a network device. So let's do just
518 that next. We will start with a description of how to collect data.</p>
519 <p>Some people will make a remark that there are tools which can do this data
520 collection for you. They are right! However, I feel it is important that
521 you understand they are not necessary. When you have to determine why
522 things went wrong you need to know how they work.</p>
523 <p>One tool used in the example has been talked about very briefly in the
524 beginning of this document, it is called SNMP. It is a way of talking
525 to networked equipment. The tool I use below is called ``snmpget'' and
526 this is how it works:</p>
527 <pre>
528    snmpget device password OID</pre>
529 <p>or</p>
530 <pre>
531    snmpget -v[version] -c[password] device OID</pre>
532 <p>For device you substitute the name, or the IP address, of your device.
533 For password you use the ``community read string'' as it is called in the
534 SNMP world.  For some devices the default of ``public'' might work, however
535 this can be disabled, altered or protected for privacy and security
536 reasons.  Read the documentation that comes with your device or program.</p>
537 <p>Then there is this parameter, called OID, which means ``object identifier''.</p>
538 <p>When you start to learn about SNMP it looks very confusing. It isn't
539 all that difficult when you look at the Management Information Base
540 (``MIB'').  It is an upside-down tree that describes data, with a single node
541 as the root and from there a number of branches.  These branches end
542 up in another node, they branch out, etc.  All the branches have a name
543 and they form the path that we follow all the way down.  The branches
544 that we follow are named: iso, org, dod, internet, mgmt and mib-2.
545 These names can also be written down as numbers and are 1 3 6 1 2 1.</p>
546 <pre>
547    iso.org.dod.internet.mgmt.mib-2 (1.3.6.1.2.1)</pre>
548 <p>There is a lot of confusion about the leading dot that some programs
549 use.  There is *no* leading dot in an OID.  However, some programs
550 can use the above part of OIDs as a default.  To indicate the difference
551 between abbreviated OIDs and full OIDs they need a leading dot when
552 you specify the complete OID.  Often those programs will leave out
553 the default portion when returning the data to you.  To make things
554 worse, they have several default prefixes ...</p>
555 <p>Ok, lets continue to the start of our OID: we had 1.3.6.1.2.1
556 From there, we are especially interested in the branch ``interfaces''
557 which has number 2 (e.g., 1.3.6.1.2.1.2 or 1.3.6.1.2.1.interfaces).</p>
558 <p>First, we have to get some SNMP program. First look if there is a
559 pre-compiled package available for your OS. This is the preferred way.
560 If not, you will have to get the sources yourself and compile those.
561 The Internet is full of sources, programs etc. Find information using
562 a search engine or whatever you prefer.</p>
563 <p>Assume you got the program. First try to collect some data that is
564 available on most systems. Remember: there is a short name for the
565 part of the tree that interests us most in the world we live in!</p>
566 <p>I will give an example which can be used on Fedora Core 3.  If it
567 doesn't work for you, work your way through the manual of snmp and
568 adapt the example to make it work.</p>
569 <pre>
570    snmpget -v2c -c public myrouter system.sysDescr.0</pre>
571 <p>The device should answer with a description of itself, perhaps an
572 empty one. Until you got a valid answer from a device, perhaps using a
573 different ``password'', or a different device, there is no point in
574 continuing.</p>
575 <pre>
576    snmpget -v2c -c public myrouter interfaces.ifNumber.0</pre>
577 <p>Hopefully you get a number as a result, the number of interfaces.
578 If so, you can carry on and try a different program called ``snmpwalk''.</p>
579 <pre>
580    snmpwalk -v2c -c public myrouter interfaces.ifTable.ifEntry.ifDescr</pre>
581 <p>If it returns with a list of interfaces, you're almost there.
582 Here's an example:
583    [user@host /home/alex]$ snmpwalk -v2c -c public cisco 2.2.1.2</p>
584 <pre>
585    interfaces.ifTable.ifEntry.ifDescr.1 = &quot;BRI0: B-Channel 1&quot;
586    interfaces.ifTable.ifEntry.ifDescr.2 = &quot;BRI0: B-Channel 2&quot;
587    interfaces.ifTable.ifEntry.ifDescr.3 = &quot;BRI0&quot; Hex: 42 52 49 30
588    interfaces.ifTable.ifEntry.ifDescr.4 = &quot;Ethernet0&quot;
589    interfaces.ifTable.ifEntry.ifDescr.5 = &quot;Loopback0&quot;</pre>
590 <p>On this cisco equipment, I would like to monitor the ``Ethernet0''
591 interface and from the above output I see that it is number four. I try:</p>
592 <pre>
593    [user@host /home/alex]$ snmpget -v2c -c public cisco 2.2.1.10.4 2.2.1.16.4</pre>
594 <pre>
595    interfaces.ifTable.ifEntry.ifInOctets.4 = 2290729126
596    interfaces.ifTable.ifEntry.ifOutOctets.4 = 1256486519</pre>
597 <p>So now I have two OIDs to monitor and they are (in full, this time):</p>
598 <pre>
599    1.3.6.1.2.1.2.2.1.10</pre>
600 <p>and</p>
601 <pre>
602    1.3.6.1.2.1.2.2.1.16</pre>
603 <p>both with an interface number of 4.</p>
604 <p>Don't get fooled, this wasn't my first try. It took some time for me too
605 to understand what all these numbers mean. It does help a lot when they
606 get translated into descriptive text... At least, when people are talking
607 about MIBs and OIDs you know what it's all about.
608 Do not forget the interface number (0 if it is not interface dependent)
609 and try snmpwalk if you don't get an answer from snmpget.</p>
610 <p>If you understand the above section and get numbers from your device, continue
611 on with this tutorial. If not, then go back and re-read this part.</p>
612 <p>
613 </p>
614 <h2><a name="a_real_world_example">A Real World Example</a></h2>
615 <p>Let the fun begin. First, create a new database. It contains data from
616 two counters, called input and output. The data is put into archives
617 that average it. They take 1, 6, 24 or 288 samples at a time.
618 They also go into archives that keep the maximum numbers. This will be
619 explained later on. The time in-between samples is 300 seconds, a good
620 starting point, which is the same as five minutes.</p>
621 <pre>
622  1 sample &quot;averaged&quot; stays 1 period of 5 minutes
623  6 samples averaged become one average on 30 minutes
624  24 samples averaged become one average on 2 hours
625  288 samples averaged become one average on 1 day</pre>
626 <p>Lets try to be compatible with MRTG which stores about the following
627 amount of data:</p>
628 <pre>
629  600 5-minute samples:    2   days and 2 hours
630  600 30-minute samples:  12.5 days
631  600 2-hour samples:     50   days
632  732 1-day samples:     732   days</pre>
633 <p>These ranges are appended, so the total amount of data stored in the
634 database is approximately 797 days. RRDtool stores the data
635 differently, it doesn't start the ``weekly'' archive where the ``daily''
636 archive stopped. For both archives the most recent data will be near
637 ``now'' and therefore we will need to keep more data than MRTG does!</p>
638 <p>We will need:</p>
639 <pre>
640  600 samples of 5 minutes  (2 days and 2 hours)
641  700 samples of 30 minutes (2 days and 2 hours, plus 12.5 days)
642  775 samples of 2 hours    (above + 50 days)
643  797 samples of 1 day      (above + 732 days, rounded up to 797)</pre>
644 <pre>
645    rrdtool create myrouter.rrd         \
646             DS:input:COUNTER:600:U:U   \
647             DS:output:COUNTER:600:U:U  \
648             RRA:AVERAGE:0.5:1:600      \
649             RRA:AVERAGE:0.5:6:700      \
650             RRA:AVERAGE:0.5:24:775     \
651             RRA:AVERAGE:0.5:288:797    \
652             RRA:MAX:0.5:1:600          \
653             RRA:MAX:0.5:6:700          \
654             RRA:MAX:0.5:24:775         \
655             RRA:MAX:0.5:288:797</pre>
656 <p>Next thing to do is to collect data and store it. Here is an example.
657 It is written partially in pseudo code,  you will have to find out what
658 to do exactly on your OS to make it work.</p>
659 <pre>
660    while not the end of the universe
661    do
662       get result of
663          snmpget router community 2.2.1.10.4
664       into variable $in
665       get result of
666          snmpget router community 2.2.1.16.4
667       into variable $out</pre>
668 <pre>
669       rrdtool update myrouter.rrd N:$in:$out</pre>
670 <pre>
671       wait for 5 minutes
672    done</pre>
673 <p>Then, after collecting data for a day, try to create an image using:</p>
674 <pre>
675    rrdtool graph myrouter-day.png --start -86400 \
676             DEF:inoctets=myrouter.rrd:input:AVERAGE \
677             DEF:outoctets=myrouter.rrd:output:AVERAGE \
678             AREA:inoctets#00FF00:&quot;In traffic&quot; \
679             LINE1:outoctets#0000FF:&quot;Out traffic&quot;</pre>
680 <p>This should produce a picture with one day worth of traffic.
681 One day is 24 hours of 60 minutes of 60 seconds: 24*60*60=86'400, we
682 start at now minus 86'400 seconds. We define (with DEFs) inoctets and
683 outoctets as the average values from the database myrouter.rrd and draw
684 an area for the ``in'' traffic and a line for the ``out'' traffic.</p>
685 <p>View the image and keep logging data for a few more days.
686 If you like, you could try the examples from the test database and
687 see if you can get various options and calculations to work.</p>
688 <p>Suggestion: Display in bytes per second and in bits per second. Make
689 the Ethernet graphics go red if they are over four megabits per
690 second.</p>
691 <p>
692 </p>
693 <h2><a name="consolidation_functions">Consolidation Functions</a></h2>
694 <p>A few paragraphs back I mentioned the possibility of keeping
695 the maximum values instead of the average values. Let's go
696 into this a bit more.</p>
697 <p>Recall all the stuff about the speed of the car. Suppose we drove at 144
698 KM/H during 5 minutes and then were stopped by the police for 25 minutes.
699 At the end of the lecture we would take our laptop and create and view the
700 image taken from the database. If we look at the second RRA we did
701 create, we would have the average from 6 samples. The samples measured
702 would be 144+0+0+0+0+0=144, divided by 30 minutes, corrected for the
703 error by 1000, translated into KM/H, with a result of 24 KM/H.
704 I would still get a ticket but not for speeding anymore :)</p>
705 <p>Obviously, in this case we shouldn't look at the averages. In some
706 cases they are handy. If you want to know how many KM you had traveled,
707 the averaged picture would be the right one to look at. On the other hand, for
708 the speed that we traveled at, the maximum numbers seen is much more
709 interesting. Later we will see more types.</p>
710 <p>It is the same for data. If you want to know the amount, look at the
711 averages. If you want to know the rate, look at the maximum.
712 Over time, they will grow apart more and more. In the last database
713 we have created, there are two archives that keep data per day. The
714 archive that keeps averages will show low numbers, the archive that
715 shows maxima will have higher numbers.</p>
716 <p>For my car this would translate in averages per day of 96/24=4 KM/H
717 (as I travel about 94 kilometers on a day) during working days, and
718 maxima of 120 KM/H (my top speed that I reach every day).</p>
719 <p>Big difference. Do not look at the second graph to estimate the
720 distances that I travel and do not look at the first graph to
721 estimate my speed. This will work if the samples are close together,
722 as they are in five minutes, but not if you average.</p>
723 <p>On some days, I go for a long ride. If I go across Europe and travel
724 for 12 hours, the first graph will rise to about 60 KM/H. The second
725 one will show 180 KM/H. This means that I traveled a distance of 60
726 KM/H times 24 H = 1440 KM. I did this with a higher speed and a
727 maximum around 180 KM/H. However, it probably doesn't mean that I
728 traveled for 8 hours at a constant speed of 180 KM/H!</p>
729 <p>This is a real example: go with the flow through Germany (fast!) and stop
730 a few times for gas and coffee. Drive slowly through Austria and the
731 Netherlands. Be careful in the mountains and villages. If you would
732 look at the graphs created from the five-minute averages you would
733 get a totally different picture. You would see the same values on the
734 average and maximum graphs (provided I measured every 300 seconds).
735 You would be able to see when I stopped, when I was in top gear, when
736 I drove over fast highways etc. The granularity of the data is much
737 higher, so you can see more. However, this takes 12 samples per hour,
738 or 288 values per day, so it would be a lot of data over a longer
739 period of time. Therefore we average it, eventually to one value per
740 day. From this one value, we cannot see much detail, of course.</p>
741 <p>Make sure you understand the last few paragraphs. There is no value
742 in only a line and a few axis, you need to know what they mean and
743 interpret the data in ana appropriate way. This is true for all data.</p>
744 <p>The biggest mistake you can make is to use the collected data for
745 something that it is not suitable for. You would be better off if
746 you didn't have the graph at all.</p>
747 <p>
748 </p>
749 <h2><a name="let_s_review_what_you_now_should_know">Let's review what you now should know</a></h2>
750 <p>You know how to create a database and can put data in it. You can get
751 the numbers out again by creating an image, do math on the data from
752 the database and view the resulte instead of the raw data.  You know
753 about the difference between averages and maxima, and when to use
754 which (or at least you should have an idea).</p>
755 <p>RRDtool can do more than what we have learned up to now. Before you
756 continue with the rest of this doc, I recommend that you reread from
757 the start and try some modifications on the examples. Make sure you
758 fully understand everything. It will be worth the effort and helps
759 you not only with the rest of this tutorial, but also in your day to day
760 monitoring long after you read this introduction.</p>
761 <p>
762 </p>
763 <h2><a name="data_source_types">Data Source Types</a></h2>
764 <p>All right, you feel like continuing. Welcome back and get ready
765 for an increased speed in the examples and explanations.</p>
766 <p>You know that in order to view a counter over time, you have to
767 take two numbers and divide the difference of them between the
768 time lapsed.  This makes sense for the examples I gave you but there
769 are other possibilities.  For instance, I'm able to retrieve the
770 temperature from my router in three places namely the inlet, the
771 so called hot-spot and the exhaust.  These values are not counters.
772 If I take the difference of the two samples and divide that by
773 300 seconds I would be asking for the temperature change per second.
774 Hopefully this is zero! If not, the computer room is probably on fire :)</p>
775 <p>So, what can we do?  We can tell RRDtool to store the values we measure
776 directly as they are (this is not entirely true but close enough). The
777 graphs we make will look much better, they will show a rather constant
778 value. I know when the router is busy (it
779 works -&gt; it uses more electricity -&gt; it generates more heat -&gt; the
780 temperature rises). I know when the doors are left open (the room is
781 air conditioned) -&gt; the warm air from the rest of the building flows into the
782 computer room -&gt; the inlet temperature rises). Etc. The data type we
783 use when creating the database before was counter, we now have a
784 different data type and thus a different name for it. It is called
785 GAUGE. There are more such data types:</p>
786 <pre>
787  - COUNTER   we already know this one
788  - GAUGE     we just learned this one
789  - DERIVE
790  - ABSOLUTE</pre>
791 <p>The two additional types are DERIVE and ABSOLUTE. Absolute can be used like
792 counter with one difference: RRDtool assumes the counter is reset when
793 it's read. That is: its delta is known without calculation by RRDtool
794 whereas RRDtool needs to calculate it for the counter type.
795 Example: our first example (12'345, 12'357, 12'363, 12'363) would read:
796 unknown, 12, 6, 0. The rest of the calculations stay the same.
797 The other one, derive, is like counter. Unlike counter, it can also
798 decrease so it can have a negative delta. Again, the rest of the
799 calculations stay the same.</p>
800 <p>Let's try them all:</p>
801 <pre>
802    rrdtool create all.rrd --start 978300900 \
803             DS:a:COUNTER:600:U:U \
804             DS:b:GAUGE:600:U:U \
805             DS:c:DERIVE:600:U:U \
806             DS:d:ABSOLUTE:600:U:U \
807             RRA:AVERAGE:0.5:1:10
808    rrdtool update all.rrd \
809             978301200:300:1:600:300    \
810             978301500:600:3:1200:600   \
811             978301800:900:5:1800:900   \
812             978302100:1200:3:2400:1200 \
813             978302400:1500:1:2400:1500 \
814             978302700:1800:2:1800:1800 \
815             978303000:2100:4:0:2100    \
816             978303300:2400:6:600:2400  \
817             978303600:2700:4:600:2700  \
818             978303900:3000:2:1200:3000
819    rrdtool graph all1.png -s 978300600 -e 978304200 -h 400 \
820             DEF:linea=all.rrd:a:AVERAGE LINE3:linea#FF0000:&quot;Line A&quot; \
821             DEF:lineb=all.rrd:b:AVERAGE LINE3:lineb#00FF00:&quot;Line B&quot; \
822             DEF:linec=all.rrd:c:AVERAGE LINE3:linec#0000FF:&quot;Line C&quot; \
823             DEF:lined=all.rrd:d:AVERAGE LINE3:lined#000000:&quot;Line D&quot;</pre>
824 <p>
825 </p>
826 <h2><a name="rrdtool_under_the_microscope">RRDtool under the Microscope</a></h2>
827 <ul>
828 <li>
829 <p>Line A is a COUNTER type, so it should continuously increment and RRDtool
830 must calculate the differences. Also, RRDtool needs to divide the
831 difference by the amount of time lapsed. This should end up as a
832 straight line at 1 (the deltas are 300, the time is 300).</p>
833 </li>
834 <li>
835 <p>Line B is of type GAUGE. These are ``real'' values so they should match
836 what we put in: a sort of a wave.</p>
837 </li>
838 <li>
839 <p>Line C is of type DERIVE. It should be a counter that can decrease. It does
840 so between 2'400 and 0, with 1'800 in-between.</p>
841 </li>
842 <li>
843 <p>Line D is of type ABSOLUTE. This is like counter but it works on
844 values without calculating the difference. The numbers are the same
845 and as you can see (hopefully) this has a different result.</p>
846 </li>
847 </ul>
848 <p>This translates in the following values, starting at 23:10 and ending
849 at 00:10 the next day (where ``u'' means unknown/unplotted):</p>
850 <pre>
851  - Line A:  u  u  1  1  1  1  1  1  1  1  1  u
852  - Line B:  u  1  3  5  3  1  2  4  6  4  2  u
853  - Line C:  u  u  2  2  2  0 -2 -6  2  0  2  u
854  - Line D:  u  1  2  3  4  5  6  7  8  9 10  u</pre>
855 <p>If your PNG shows all this, you know you have entered the data correctly,
856 the RRDtool executable is working properly, your viewer doesn't fool you,
857 and you successfully entered the year 2000 :)</p>
858 <p>You could try the same example four times, each time with only one of
859 the lines.</p>
860 <p>Let's go over the data again:</p>
861 <ul>
862 <li>
863 <p>Line A: 300,600,900 and so on. The counter delta is a constant 300 and
864 so is the time delta. A number divided by itself is always 1 (except
865 when dividing by zero which is undefined/illegal).</p>
866 <p>Why is it that the first point is unknown? We do know what we put into
867 the database, right? True, But we didn't have a value to calculate the delta
868 from, so we don't know where we started. It would be wrong to assume we
869 started at zero so we don't!</p>
870 </li>
871 <li>
872 <p>Line B: There is nothing to calculate. The numbers are as they are.</p>
873 </li>
874 <li>
875 <p>Line C: Again, the start-out value is unknown. The same story is holds
876 as for line A. In this case the deltas are not constant, therefore the line
877 is not either. If we would put the same numbers in the database as we did for
878 line A, we would have gotten the same line. Unlike type counter,
879 this type can decrease and I hope to show you later on why
880 this makes a difference.</p>
881 </li>
882 <li>
883 <p>Line D: Here the device calculates the deltas. Therefore we DO know the
884 first delta and it is plotted. We had the same input as with line A, but
885 the meaning of this input is different and thus the line is different.
886 In this case the deltas increase each time with 300. The time delta
887 stays at a constant 300 and therefore the division of the two gives
888 increasing values.</p>
889 </li>
890 </ul>
891 <p>
892 </p>
893 <h2><a name="counter_wraps">Counter Wraps</a></h2>
894 <p>There are a few more basics to show. Some important options are still to
895 be covered and we haven't look at counter wraps yet. First the counter wrap:
896 In our car we notice that the counter shows 999'987. We travel 20 KM and
897 the counter should go to 1'000'007. Unfortunately, there are only six digits
898 on our counter so it really shows 000'007. If we would plot that on a type
899 DERIVE, it would mean that the counter was set back 999'980 KM. It wasn't,
900 and there has to be some protection for this. This protection is only
901 available for type COUNTER which should be used for this kind of counter
902 anyways. How does it work? Type counter should never decrease and
903 therefore RRDtool must assume it wrapped if it does decrease!
904 If the delta is negative, this can be compensated for by adding the
905 maximum value of the counter + 1. For our car this would be:</p>
906 <pre>
907  Delta = 7 - 999'987 = -999'980    (instead of 1'000'007-999'987=20)</pre>
908 <pre>
909  Real delta = -999'980 + 999'999 + 1 = 20</pre>
910 <p>At the time of writing this document, RRDtool knows of counters that
911 are either 32 bits or 64 bits of size. These counters can handle the
912 following different values:</p>
913 <pre>
914  - 32 bits: 0 ..           4'294'967'295
915  - 64 bits: 0 .. 18'446'744'073'709'551'615</pre>
916 <p>If these numbers look strange to you, you can view them in
917 their hexadecimal form:</p>
918 <pre>
919  - 32 bits: 0 ..         FFFFFFFF
920  - 64 bits: 0 .. FFFFFFFFFFFFFFFF</pre>
921 <p>RRDtool handles both counters the same. If an overflow occurs and
922 the delta would be negative, RRDtool first adds the maximum of a small
923 counter + 1 to the delta. If the delta is still negative, it had to be
924 the large counter that wrapped. Add the maximum possible value of the
925 large counter + 1 and subtract the erroneously added small value.</p>
926 <p>There is a risk in this: suppose the large counter wrapped while adding
927 a huge delta, it could happen, theoretically, that adding the smaller value
928 would make the delta positive. In this unlikely case the results would
929 not be correct. The increase should be nearly as high as the maximum
930 counter value for that to happen, so chances are you would have several
931 other problems as well and this particular problem would not even be
932 worth thinking about. Even though, I did include an example, so you
933 can judge for yourself.</p>
934 <p>The next section gives you some numerical examples for counter-wraps.
935 Try to do the calculations yourself or just believe me if your calculator
936 can't handle the numbers :)</p>
937 <p>Correction numbers:</p>
938 <pre>
939  - 32 bits: (4'294'967'295 + 1) =                                4'294'967'296
940  - 64 bits: (18'446'744'073'709'551'615 + 1)
941                                     - correction1 = 18'446'744'069'414'584'320</pre>
942 <pre>
943  Before:        4'294'967'200
944  Increase:                100
945  Should become: 4'294'967'300
946  But really is:             4
947  Delta:        -4'294'967'196
948  Correction1:  -4'294'967'196 + 4'294'967'296 = 100</pre>
949 <pre>
950  Before:        18'446'744'073'709'551'000
951  Increase:                             800
952  Should become: 18'446'744'073'709'551'800
953  But really is:                        184
954  Delta:        -18'446'744'073'709'550'816
955  Correction1:  -18'446'744'073'709'550'816
956                                 + 4'294'967'296 = -18'446'744'069'414'583'520
957  Correction2:  -18'446'744'069'414'583'520
958                    + 18'446'744'069'414'584'320 = 800</pre>
959 <pre>
960  Before:        18'446'744'073'709'551'615 ( maximum value )
961  Increase:      18'446'744'069'414'584'320 ( absurd increase, minimum for
962  Should become: 36'893'488'143'124'135'935             this example to work )
963  But really is: 18'446'744'069'414'584'319
964  Delta:                     -4'294'967'296
965  Correction1:  -4'294'967'296 + 4'294'967'296 = 0
966  (not negative -&gt; no correction2)</pre>
967 <pre>
968  Before:        18'446'744'073'709'551'615 ( maximum value )
969  Increase:      18'446'744'069'414'584'319 ( one less increase )
970  Should become: 36'893'488'143'124'135'934
971  But really is: 18'446'744'069'414'584'318
972  Delta:                     -4'294'967'297
973  Correction1:  -4'294'967'297 + 4'294'967'296 = -1
974  Correction2:  -1 + 18'446'744'069'414'584'320 = 18'446'744'069'414'584'319</pre>
975 <p>As you can see from the last two examples, you need strange numbers
976 for RRDtool to fail (provided it's bug free of course), so this should
977 not happen. However, SNMP or whatever method you choose to collect the
978 data, might also report wrong numbers occasionally.  We can't prevent all
979 errors, but there are some things we can do. The RRDtool ``create'' command
980 takes two special parameters for this. They define
981 the minimum and maximum allowed values. Until now, we used ``U'', meaning
982 ``unknown''. If you provide values for one or both of them and if RRDtool
983 receives data points that are outside these limits, it will ignore those
984 values. For a thermometer in degrees Celsius, the absolute minimum is
985 just under -273. For my router, I can assume this minimum is much higher
986 so I would set it to 10, where as the maximum temperature I would
987 set to 80. Any higher and the device would be out of order.</p>
988 <p>For the speed of my car, I would never expect negative numbers and
989 also I would not expect a speed  higher than 230. Anything else,
990 and there must have been an error. Remember: the opposite is not true,
991 if the numbers pass this check, it doesn't mean that they are
992 correct. Always judge the graph with a healthy dose of suspicion if it
993 seems weird to you.</p>
994 <p>
995 </p>
996 <h2><a name="data_resampling">Data Resampling</a></h2>
997 <p>One important feature of RRDtool has not been explained yet: it is
998 virtually impossible to collect data and feed it into RRDtool on exact
999 intervals. RRDtool therefore interpolates the data, so they are stored
1000 on exact intervals. If you do not know what this means or how it
1001 works, then here's the help you seek:</p>
1002 <p>Suppose a counter increases by exactly one for every second. You want
1003 to measure it in 300 seconds intervals. You should retrieve values
1004 that are exactly 300 apart. However, due to various circumstances you
1005 are a few seconds late and the interval is 303. The delta will also be
1006 303 in that case. Obviously, RRDtool should not put 303 in the database
1007 and make you believe that the counter increased by 303 in 300 seconds.
1008 This is where RRDtool interpolates: it alters the 303 value as if it
1009 would have been stored earlier and it will be 300 in 300 seconds.
1010 Next time you are at exactly the right time. This means that the current
1011 interval is 297 seconds and also the counter increased by 297. Again,
1012 RRDtool interpolates and stores 300 as it should be.</p>
1013 <pre>
1014       in the RRD                 in reality</pre>
1015 <pre>
1016  time+000:   0 delta=&quot;U&quot;   time+000:    0 delta=&quot;U&quot;
1017  time+300: 300 delta=300   time+300:  300 delta=300
1018  time+600: 600 delta=300   time+603:  603 delta=303
1019  time+900: 900 delta=300   time+900:  900 delta=297</pre>
1020 <p>Let's create two identical databases. I've chosen the time range 920'805'000
1021 to 920'805'900 as this goes very well with the example numbers.</p>
1022 <pre>
1023    rrdtool create seconds1.rrd   \
1024       --start 920804700          \
1025       DS:seconds:COUNTER:600:U:U \
1026       RRA:AVERAGE:0.5:1:24</pre>
1027 <p>Make a copy</p>
1028 <pre>
1029    for Unix: cp seconds1.rrd seconds2.rrd
1030    for Dos:  copy seconds1.rrd seconds2.rrd
1031    for vms:  how would I know :)</pre>
1032 <p>Put in some data</p>
1033 <pre>
1034    rrdtool update seconds1.rrd \
1035       920805000:000 920805300:300 920805600:600 920805900:900
1036    rrdtool update seconds2.rrd \
1037       920805000:000 920805300:300 920805603:603 920805900:900</pre>
1038 <p>Create output</p>
1039 <pre>
1040    rrdtool graph seconds1.png                       \
1041       --start 920804700 --end 920806200             \
1042       --height 200                                  \
1043       --upper-limit 1.05 --lower-limit 0.95 --rigid \
1044       DEF:seconds=seconds1.rrd:seconds:AVERAGE      \
1045       CDEF:unknown=seconds,UN                       \
1046       LINE2:seconds#0000FF                          \
1047       AREA:unknown#FF0000
1048    rrdtool graph seconds2.png                       \
1049       --start 920804700 --end 920806200             \
1050       --height 200                                  \
1051       --upper-limit 1.05 --lower-limit 0.95 --rigid \
1052       DEF:seconds=seconds2.rrd:seconds:AVERAGE      \
1053       CDEF:unknown=seconds,UN                       \
1054       LINE2:seconds#0000FF                          \
1055       AREA:unknown#FF0000</pre>
1056 <p>View both images together (add them to your index.html file)
1057 and compare. Both graphs should show the same, despite the
1058 input being different.</p>
1059 <p>
1060 </p>
1061 <hr />
1062 <h1><a name="wrapup">WRAPUP</a></h1>
1063 <p>It's time now to wrap up this tutorial. We covered all the basics for
1064 you to be able to work with RRDtool and to read the additional
1065 documentation available. There is plenty more to discover about
1066 RRDtool and you will find more and more uses for this package. You can
1067 easly create graphs using just the examples provided and using only
1068 RRDtool. You can also use one of the front ends to RRDtool that are
1069 available.</p>
1070 <p>
1071 </p>
1072 <hr />
1073 <h1><a name="mailinglist">MAILINGLIST</a></h1>
1074 <p>Remember to subscribe to the RRDtool mailing list. Even if you are not
1075 answering to mails that come by, it helps both you and the rest of the
1076 users. A lot of the stuff that I know about MRTG (and therefore about
1077 RRDtool) I've learned while just reading the list without posting to
1078 it. I did not need to ask the basic questions as they are answered in
1079 the FAQ (read it!) and in various mails by other users. With
1080 thousands of users all over the world, there will always be people who
1081 ask questions that you can answer because you read this and other
1082 documentation and they didn't.</p>
1083 <p>
1084 </p>
1085 <hr />
1086 <h1><a name="see_also">SEE ALSO</a></h1>
1087 <p>The RRDtool manpages</p>
1088 <p>
1089 </p>
1090 <hr />
1091 <h1><a name="author">AUTHOR</a></h1>
1092 <p>I hope you enjoyed the examples and their descriptions. If you do, help
1093 other people by pointing them to this document when they are asking
1094 basic questions. They will not only get their answers, but at the same
1095 time learn a whole lot more.</p>
1096 <p>Alex van den Bogaerdt
1097 &lt;<a href="mailto:alex@ergens.op.het.net">alex@ergens.op.het.net</a>&gt;</p>
1099 </body>
1101 </html>