Code

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