Code

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