Code

00998d8e6739c4d091cca9fbba716c4c79a012d4
[pkg-rrdtool.git] / doc / rrdtutorial.1
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
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.  \*(C+ will
29 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
30 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
31 .\" nothing in troff, for use with C<>.
32 .tr \(*W-
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-02-21" "1.3.7" "rrdtool"
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 .Sh "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 .Sh "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 .Sh "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 .Sh "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 .Sh "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 .Sh "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 .Sh "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 .Sh "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 15
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 .Ve
434 .PP
435 .Vb 16
436 \& 920804700: nan
437 \& 920805000: 4.0000000000e\-02
438 \& 920805300: 2.0000000000e\-02
439 \& 920805600: 0.0000000000e+00
440 \& 920805900: 0.0000000000e+00
441 \& 920806200: 3.3333333333e\-02
442 \& 920806500: 3.3333333333e\-02
443 \& 920806800: 3.3333333333e\-02
444 \& 920807100: 2.0000000000e\-02
445 \& 920807400: 2.0000000000e\-02
446 \& 920807700: 2.0000000000e\-02
447 \& 920808000: 1.3333333333e\-02
448 \& 920808300: 1.6666666667e\-02
449 \& 920808600: 6.6666666667e\-03
450 \& 920808900: 3.3333333333e\-03
451 \& 920809200: nan
452 .Ve
453 .PP
454 If it doesn't, something may be wrong.  Perhaps your \s-1OS\s0 will print
455 \&\*(L"NaN\*(R" in a different form. \*(L"NaN\*(R" stands for \*(L"Not A Number\*(R".  If your \s-1OS\s0
456 writes \*(L"U\*(R" or \*(L"\s-1UNKN\s0\*(R" or something similar that's okay.  If something
457 else is wrong, it will probably be due to an error you made (assuming
458 that my tutorial is correct of course :\-). In that case: delete the
459 database and try again. 
460 .PP
461 The meaning of the above output will become clear below.
462 .Sh "Time to create some graphics"
463 .IX Subsection "Time to create some graphics"
464 Try the following command:
465 .PP
466 .Vb 4
467 \& rrdtool graph speed.png                                 \e
468 \&         \-\-start 920804400 \-\-end 920808000               \e
469 \&         DEF:myspeed=test.rrd:speed:AVERAGE              \e
470 \&         LINE2:myspeed#FF0000
471 .Ve
472 .PP
473 This will create speed.png which starts at 12:00 and ends at 13:00.
474 There is a definition of a variable called myspeed, using the data from \s-1RRA\s0
475 \&\*(L"speed\*(R" out of database \*(L"test.rrd\*(R". The line drawn is 2 pixels high
476 and represents the variable myspeed. The color is red (specified by
477 its rgb\-representation, see below).
478 .PP
479 You'll notice that the start of the graph is not at 12:00 but at 12:05.
480 This is because we have insufficient data to tell the average before
481 that time. This will only happen when you miss some samples, this will
482 not happen a lot, hopefully.
483 .PP
484 If this has worked: congratulations! If not, check what went wrong.
485 .PP
486 The colors are built up from red, green and blue. For each of the
487 components, you specify how much to use in hexadecimal where 00 means
488 not included and \s-1FF\s0 means fully included.
489 The \*(L"color\*(R" white is a mixture of red, green and blue: \s-1FFFFFF\s0
490 The \*(L"color\*(R" black is all colors off: 000000
491 .PP
492 .Vb 5
493 \&   red     #FF0000
494 \&   green   #00FF00
495 \&   blue    #0000FF
496 \&   magenta #FF00FF     (mixed red with blue)
497 \&   gray    #555555     (one third of all components)
498 .Ve
499 .PP
500 Additionally you can (with a recent RRDtool)  add an alpha channel
501 (transparency).  The default will be \*(L"\s-1FF\s0\*(R" which means non\-transparent.
502 .PP
503 The \s-1PNG\s0 you just created can be displayed using your favorite image
504 viewer.  Web browsers will display the \s-1PNG\s0 via the \s-1URL\s0
505 \&\*(L"file:///the/path/to/speed.png\*(R"
506 .Sh "Graphics with some math"
507 .IX Subsection "Graphics with some math"
508 When looking at the image, you notice that the horizontal axis is labeled
509 12:10, 12:20, 12:30, 12:40 and 12:50. Sometimes a label doesn't fit (12:00
510 and 13:00 would be likely candidates) so they are skipped.
511 .PP
512 The vertical axis displays the range we entered. We provided
513 kilometers and when divided by 300 seconds, we get very small
514 numbers. To be exact, the first value was 12 (12357\-12345) and divided
515 by 300 this makes 0.04, which is displayed by RRDtool as \*(L"40 m\*(R"
516 meaning \*(L"40/1000\*(R". The \*(L"m\*(R" (milli) has nothing to do with meters (also m),
517 kilometers or millimeters! RRDtool doesn't know about the physical
518 units of our data, it just works with dimensionless numbers.
519 .PP
520 If we had measured our distances in meters, this would have been
521 (12357000\-12345000)/300 = 12000/300 = 40.
522 .PP
523 As most people have a better feel for numbers in this range, we'll
524 correct that. We could recreate our database and store the correct
525 data, but there is a better way: we do some calculations while creating
526 the png file!
527 .PP
528 .Vb 6
529 \&   rrdtool graph speed2.png                           \e
530 \&      \-\-start 920804400 \-\-end 920808000               \e
531 \&      \-\-vertical\-label m/s                            \e
532 \&      DEF:myspeed=test.rrd:speed:AVERAGE              \e
533 \&      CDEF:realspeed=myspeed,1000,\e*                  \e
534 \&      LINE2:realspeed#FF0000
535 .Ve
536 .PP
537 Note: I need to escape the multiplication operator * with a backslash.
538 If I don't, the operating system may interpret it and use it for file
539 name expansion. You could also place the line within quotation marks
540 like so:
541 .PP
542 .Vb 1
543 \&      "CDEF:realspeed=myspeed,1000,*"                  \e
544 .Ve
545 .PP
546 It boils down to: it is RRDtool which should see *, not your shell.
547 And it is your shell interpreting \e, not RRDtool. You may need to
548 adjust examples accordingly if you happen to use an operating
549 system or shell which behaves differently.
550 .PP
551 After viewing this \s-1PNG\s0, you notice the \*(L"m\*(R" (milli) has
552 disappeared. This it what the correct result would be. Also, a label
553 has been added to the image.  Apart from the things mentioned above,
554 the \s-1PNG\s0 should look the same.
555 .PP
556 The calculations are specified in the \s-1CDEF\s0 part above and are in
557 Reverse Polish Notation (\*(L"\s-1RPN\s0\*(R"). What we requested RRDtool to do is:
558 \&\*(L"take the data source myspeed and the number 1000; multiply
559 those\*(R". Don't bother with \s-1RPN\s0 yet, it will be explained later on in
560 more detail. Also, you may want to read my tutorial on CDEFs and Steve
561 Rader's tutorial on \s-1RPN\s0. But first finish this tutorial.
562 .PP
563 Hang on! If we can multiply values with 1000, it should also be possible
564 to display kilometers per hour from the same data!
565 .PP
566 To change a value that is measured in meters per second:
567 .PP
568 .Vb 3
569 \& Calculate meters per hour:     value * 3600
570 \& Calculate kilometers per hour: value / 1000
571 \& Together this makes:           value * (3600/1000) or value * 3.6
572 .Ve
573 .PP
574 In our example database we made a mistake and we need to compensate for
575 this by multiplying with 1000. Applying that correction:
576 .PP
577 .Vb 1
578 \& value * 3.6  * 1000 == value * 3600
579 .Ve
580 .PP
581 Now let's create this \s-1PNG\s0, and add some more magic ...
582 .PP
583 .Vb 10
584 \& rrdtool graph speed3.png                             \e
585 \&      \-\-start 920804400 \-\-end 920808000               \e
586 \&      \-\-vertical\-label km/h                           \e
587 \&      DEF:myspeed=test.rrd:speed:AVERAGE              \e
588 \&      "CDEF:kmh=myspeed,3600,*"                       \e
589 \&      CDEF:fast=kmh,100,GT,kmh,0,IF                   \e
590 \&      CDEF:good=kmh,100,GT,0,kmh,IF                   \e
591 \&      HRULE:100#0000FF:"Maximum allowed"              \e
592 \&      AREA:good#00FF00:"Good speed"                   \e
593 \&      AREA:fast#FF0000:"Too fast"
594 .Ve
595 .PP
596 Note: here we use another means to escape the * operator by enclosing
597 the whole string in double quotes.
598 .PP
599 This graph looks much better. Speed is shown in km/h and there is even
600 an extra line with the maximum allowed speed (on the road I travel
601 on). I also changed the colors used to display speed and changed it
602 from a line into an area.
603 .PP
604 The calculations are more complex now. For speed measurements within
605 the speed limit they are:
606 .PP
607 .Vb 2
608 \&   Check if kmh is greater than 100    ( kmh,100 ) GT
609 \&   If so, return 0, else kmh           ((( kmh,100 ) GT ), 0, kmh) IF
610 .Ve
611 .PP
612 For values above the speed limit:
613 .PP
614 .Vb 2
615 \&   Check if kmh is greater than 100    ( kmh,100 ) GT
616 \&   If so, return kmh, else return 0    ((( kmh,100) GT ), kmh, 0) IF
617 .Ve
618 .Sh "Graphics Magic"
619 .IX Subsection "Graphics Magic"
620 I like to believe there are virtually no limits to how RRDtool graph
621 can manipulate data. I will not explain how it works, but look at the
622 following \s-1PNG:\s0
623 .PP
624 .Vb 13
625 \&   rrdtool graph speed4.png                           \e
626 \&      \-\-start 920804400 \-\-end 920808000               \e
627 \&      \-\-vertical\-label km/h                           \e
628 \&      DEF:myspeed=test.rrd:speed:AVERAGE              \e
629 \&      CDEF:nonans=myspeed,UN,0,myspeed,IF             \e
630 \&      CDEF:kmh=nonans,3600,*                          \e
631 \&      CDEF:fast=kmh,100,GT,100,0,IF                   \e
632 \&      CDEF:over=kmh,100,GT,kmh,100,\-,0,IF             \e
633 \&      CDEF:good=kmh,100,GT,0,kmh,IF                   \e
634 \&      HRULE:100#0000FF:"Maximum allowed"              \e
635 \&      AREA:good#00FF00:"Good speed"                   \e
636 \&      AREA:fast#550000:"Too fast"                     \e
637 \&      STACK:over#FF0000:"Over speed"
638 .Ve
639 .PP
640 Remember the note in the beginning?  I had to remove unknown data from
641 this example. The 'nonans' \s-1CDEF\s0 is new, and the 6th line (which used to
642 be the 5th line) used to read 'CDEF:kmh=myspeed,3600,*'
643 .PP
644 Let's create a quick and dirty \s-1HTML\s0 page to view the three PNGs:
645 .PP
646 .Vb 7
647 \&   <HTML><HEAD><TITLE>Speed</TITLE></HEAD><BODY>
648 \&   <IMG src="speed2.png" alt="Speed in meters per second">
649 \&   <BR>
650 \&   <IMG src="speed3.png" alt="Speed in kilometers per hour">
651 \&   <BR>
652 \&   <IMG src="speed4.png" alt="Traveled too fast?">
653 \&   </BODY></HTML>
654 .Ve
655 .PP
656 Name the file \*(L"speed.html\*(R" or similar, and look at it in your web browser.
657 .PP
658 Now, all you have to do is measure the values regularly and update the
659 database.  When you want to view the data, recreate the PNGs and make
660 sure to refresh them in your browser. (Note: just clicking reload may
661 not be enough, especially when proxies are involved.  Try shift-reload
662 or ctrl\-F5).
663 .Sh "Updates in Reality"
664 .IX Subsection "Updates in Reality"
665 We've already used the \f(CW\*(C`update\*(C'\fR command: it took one or more
666 parameters in the form of \*(L"<time>:<value>\*(R". You'll be glad to know
667 that you can specify the current time by filling in a \*(L"N\*(R" as the time.
668 Or you could use the \*(L"time\*(R" function in Perl (the shortest example in
669 this tutorial):
670 .PP
671 .Vb 1
672 \&   perl \-e \(aqprint time, "\en" \(aq
673 .Ve
674 .PP
675 How to run a program on regular intervals is \s-1OS\s0 specific. But here is
676 an example in pseudo code:
677 .PP
678 .Vb 2
679 \&   \- Get the value and put it in variable "$speed"
680 \&   \- rrdtool update speed.rrd N:$speed
681 .Ve
682 .PP
683 (do not try this with our test database, we'll use it in further examples)
684 .PP
685 This is all. Run the above script every five minutes. When you need to know
686 what the graphs look like, run the examples above. You could put them
687 in a script as well. After running that script, view the page
688 index.html we created above.
689 .Sh "Some words on \s-1SNMP\s0"
690 .IX Subsection "Some words on SNMP"
691 I can imagine very few people that will be able to get real data from
692 their car every five minutes. All other people will have to settle for
693 some other kind of counter. You could measure the number of pages
694 printed by a printer, for example, the cups of coffee made by the
695 coffee machine, a device that counts the electricity used,
696 whatever. Any incrementing counter can be monitored and graphed using
697 the stuff you learned so far. Later on we will also be able to monitor
698 other types of values like temperature.
699 .PP
700 Many people interested in RRDtool will use the counter that keeps track
701 of octets (bytes) transfered by a network device. So let's do just
702 that next. We will start with a description of how to collect data.
703 .PP
704 Some people will make a remark that there are tools which can do this data
705 collection for you. They are right! However, I feel it is important that
706 you understand they are not necessary. When you have to determine why
707 things went wrong you need to know how they work.
708 .PP
709 One tool used in the example has been talked about very briefly in the
710 beginning of this document, it is called \s-1SNMP\s0. It is a way of talking
711 to networked equipment. The tool I use below is called \*(L"snmpget\*(R" and
712 this is how it works:
713 .PP
714 .Vb 1
715 \&   snmpget device password OID
716 .Ve
717 .PP
718 or
719 .PP
720 .Vb 1
721 \&   snmpget \-v[version] \-c[password] device OID
722 .Ve
723 .PP
724 For device you substitute the name, or the \s-1IP\s0 address, of your device.
725 For password you use the \*(L"community read string\*(R" as it is called in the
726 \&\s-1SNMP\s0 world.  For some devices the default of \*(L"public\*(R" might work, however
727 this can be disabled, altered or protected for privacy and security
728 reasons.  Read the documentation that comes with your device or program.
729 .PP
730 Then there is this parameter, called \s-1OID\s0, which means \*(L"object identifier\*(R".
731 .PP
732 When you start to learn about \s-1SNMP\s0 it looks very confusing. It isn't
733 all that difficult when you look at the Management Information Base
734 (\*(L"\s-1MIB\s0\*(R").  It is an upside-down tree that describes data, with a single node
735 as the root and from there a number of branches.  These branches end
736 up in another node, they branch out, etc.  All the branches have a name
737 and they form the path that we follow all the way down.  The branches
738 that we follow are named: iso, org, dod, internet, mgmt and mib\-2.
739 These names can also be written down as numbers and are 1 3 6 1 2 1.
740 .PP
741 .Vb 1
742 \&   iso.org.dod.internet.mgmt.mib\-2 (1.3.6.1.2.1)
743 .Ve
744 .PP
745 There is a lot of confusion about the leading dot that some programs
746 use.  There is *no* leading dot in an \s-1OID\s0.  However, some programs
747 can use the above part of OIDs as a default.  To indicate the difference
748 between abbreviated OIDs and full OIDs they need a leading dot when
749 you specify the complete \s-1OID\s0.  Often those programs will leave out
750 the default portion when returning the data to you.  To make things
751 worse, they have several default prefixes ...
752 .PP
753 Ok, lets continue to the start of our \s-1OID:\s0 we had 1.3.6.1.2.1
754 From there, we are especially interested in the branch \*(L"interfaces\*(R"
755 which has number 2 (e.g., 1.3.6.1.2.1.2 or 1.3.6.1.2.1.interfaces).
756 .PP
757 First, we have to get some \s-1SNMP\s0 program. First look if there is a
758 pre-compiled package available for your \s-1OS\s0. This is the preferred way.
759 If not, you will have to get the sources yourself and compile those.
760 The Internet is full of sources, programs etc. Find information using
761 a search engine or whatever you prefer.
762 .PP
763 Assume you got the program. First try to collect some data that is
764 available on most systems. Remember: there is a short name for the
765 part of the tree that interests us most in the world we live in!
766 .PP
767 I will give an example which can be used on Fedora Core 3.  If it
768 doesn't work for you, work your way through the manual of snmp and
769 adapt the example to make it work.
770 .PP
771 .Vb 1
772 \&   snmpget \-v2c \-c public myrouter system.sysDescr.0
773 .Ve
774 .PP
775 The device should answer with a description of itself, perhaps an
776 empty one. Until you got a valid answer from a device, perhaps using a
777 different \*(L"password\*(R", or a different device, there is no point in
778 continuing.
779 .PP
780 .Vb 1
781 \&   snmpget \-v2c \-c public myrouter interfaces.ifNumber.0
782 .Ve
783 .PP
784 Hopefully you get a number as a result, the number of interfaces.
785 If so, you can carry on and try a different program called \*(L"snmpwalk\*(R".
786 .PP
787 .Vb 1
788 \&   snmpwalk \-v2c \-c public myrouter interfaces.ifTable.ifEntry.ifDescr
789 .Ve
790 .PP
791 If it returns with a list of interfaces, you're almost there.
792 Here's an example:
793    [user@host /home/alex]$ snmpwalk \-v2c \-c public cisco 2.2.1.2
794 .PP
795 .Vb 5
796 \&   interfaces.ifTable.ifEntry.ifDescr.1 = "BRI0: B\-Channel 1"
797 \&   interfaces.ifTable.ifEntry.ifDescr.2 = "BRI0: B\-Channel 2"
798 \&   interfaces.ifTable.ifEntry.ifDescr.3 = "BRI0" Hex: 42 52 49 30
799 \&   interfaces.ifTable.ifEntry.ifDescr.4 = "Ethernet0"
800 \&   interfaces.ifTable.ifEntry.ifDescr.5 = "Loopback0"
801 .Ve
802 .PP
803 On this cisco equipment, I would like to monitor the \*(L"Ethernet0\*(R"
804 interface and from the above output I see that it is number four. I try:
805 .PP
806 .Vb 1
807 \&   [user@host /home/alex]$ snmpget \-v2c \-c public cisco 2.2.1.10.4 2.2.1.16.4
808 .Ve
809 .PP
810 .Vb 2
811 \&   interfaces.ifTable.ifEntry.ifInOctets.4 = 2290729126
812 \&   interfaces.ifTable.ifEntry.ifOutOctets.4 = 1256486519
813 .Ve
814 .PP
815 So now I have two OIDs to monitor and they are (in full, this time):
816 .PP
817 .Vb 1
818 \&   1.3.6.1.2.1.2.2.1.10
819 .Ve
820 .PP
821 and
822 .PP
823 .Vb 1
824 \&   1.3.6.1.2.1.2.2.1.16
825 .Ve
826 .PP
827 both with an interface number of 4.
828 .PP
829 Don't get fooled, this wasn't my first try. It took some time for me too
830 to understand what all these numbers mean. It does help a lot when they
831 get translated into descriptive text... At least, when people are talking
832 about MIBs and OIDs you know what it's all about.
833 Do not forget the interface number (0 if it is not interface dependent)
834 and try snmpwalk if you don't get an answer from snmpget.
835 .PP
836 If you understand the above section and get numbers from your device, continue
837 on with this tutorial. If not, then go back and re-read this part.
838 .Sh "A Real World Example"
839 .IX Subsection "A Real World Example"
840 Let the fun begin. First, create a new database. It contains data from
841 two counters, called input and output. The data is put into archives
842 that average it. They take 1, 6, 24 or 288 samples at a time.
843 They also go into archives that keep the maximum numbers. This will be
844 explained later on. The time in-between samples is 300 seconds, a good
845 starting point, which is the same as five minutes.
846 .PP
847 .Vb 4
848 \& 1 sample "averaged" stays 1 period of 5 minutes
849 \& 6 samples averaged become one average on 30 minutes
850 \& 24 samples averaged become one average on 2 hours
851 \& 288 samples averaged become one average on 1 day
852 .Ve
853 .PP
854 Lets try to be compatible with \s-1MRTG\s0 which stores about the following
855 amount of data:
856 .PP
857 .Vb 4
858 \& 600 5\-minute samples:    2   days and 2 hours
859 \& 600 30\-minute samples:  12.5 days
860 \& 600 2\-hour samples:     50   days
861 \& 732 1\-day samples:     732   days
862 .Ve
863 .PP
864 These ranges are appended, so the total amount of data stored in the
865 database is approximately 797 days. RRDtool stores the data
866 differently, it doesn't start the \*(L"weekly\*(R" archive where the \*(L"daily\*(R"
867 archive stopped. For both archives the most recent data will be near
868 \&\*(L"now\*(R" and therefore we will need to keep more data than \s-1MRTG\s0 does!
869 .PP
870 We will need:
871 .PP
872 .Vb 4
873 \& 600 samples of 5 minutes  (2 days and 2 hours)
874 \& 700 samples of 30 minutes (2 days and 2 hours, plus 12.5 days)
875 \& 775 samples of 2 hours    (above + 50 days)
876 \& 797 samples of 1 day      (above + 732 days, rounded up to 797)
877 .Ve
878 .PP
879 .Vb 11
880 \&   rrdtool create myrouter.rrd         \e
881 \&            DS:input:COUNTER:600:U:U   \e
882 \&            DS:output:COUNTER:600:U:U  \e
883 \&            RRA:AVERAGE:0.5:1:600      \e
884 \&            RRA:AVERAGE:0.5:6:700      \e
885 \&            RRA:AVERAGE:0.5:24:775     \e
886 \&            RRA:AVERAGE:0.5:288:797    \e
887 \&            RRA:MAX:0.5:1:600          \e
888 \&            RRA:MAX:0.5:6:700          \e
889 \&            RRA:MAX:0.5:24:775         \e
890 \&            RRA:MAX:0.5:288:797
891 .Ve
892 .PP
893 Next thing to do is to collect data and store it. Here is an example.
894 It is written partially in pseudo code,  you will have to find out what
895 to do exactly on your \s-1OS\s0 to make it work.
896 .PP
897 .Vb 8
898 \&   while not the end of the universe
899 \&   do
900 \&      get result of
901 \&         snmpget router community 2.2.1.10.4
902 \&      into variable $in
903 \&      get result of
904 \&         snmpget router community 2.2.1.16.4
905 \&      into variable $out
906 .Ve
907 .PP
908 .Vb 1
909 \&      rrdtool update myrouter.rrd N:$in:$out
910 .Ve
911 .PP
912 .Vb 2
913 \&      wait for 5 minutes
914 \&   done
915 .Ve
916 .PP
917 Then, after collecting data for a day, try to create an image using:
918 .PP
919 .Vb 5
920 \&   rrdtool graph myrouter\-day.png \-\-start \-86400 \e
921 \&            DEF:inoctets=myrouter.rrd:input:AVERAGE \e
922 \&            DEF:outoctets=myrouter.rrd:output:AVERAGE \e
923 \&            AREA:inoctets#00FF00:"In traffic" \e
924 \&            LINE1:outoctets#0000FF:"Out traffic"
925 .Ve
926 .PP
927 This should produce a picture with one day worth of traffic.
928 One day is 24 hours of 60 minutes of 60 seconds: 24*60*60=86400, we
929 start at now minus 86400 seconds. We define (with DEFs) inoctets and
930 outoctets as the average values from the database myrouter.rrd and draw
931 an area for the \*(L"in\*(R" traffic and a line for the \*(L"out\*(R" traffic.
932 .PP
933 View the image and keep logging data for a few more days.
934 If you like, you could try the examples from the test database and
935 see if you can get various options and calculations to work.
936 .PP
937 Suggestion: Display in bytes per second and in bits per second. Make
938 the Ethernet graphics go red if they are over four megabits per
939 second.
940 .Sh "Consolidation Functions"
941 .IX Subsection "Consolidation Functions"
942 A few paragraphs back I mentioned the possibility of keeping
943 the maximum values instead of the average values. Let's go
944 into this a bit more.
945 .PP
946 Recall all the stuff about the speed of the car. Suppose we drove at 144
947 km/h during 5 minutes and then were stopped by the police for 25 minutes.
948 At the end of the lecture we would take our laptop and create and view the
949 image taken from the database. If we look at the second \s-1RRA\s0 we did
950 create, we would have the average from 6 samples. The samples measured
951 would be 144+0+0+0+0+0=144, divided by 30 minutes, corrected for the
952 error by 1000, translated into km/h, with a result of 24 km/h.
953 I would still get a ticket but not for speeding anymore :)
954 .PP
955 Obviously, in this case we shouldn't look at the averages. In some
956 cases they are handy. If you want to know how many km you had traveled,
957 the averaged picture would be the right one to look at. On the other hand, for
958 the speed that we traveled at, the maximum numbers seen is much more
959 interesting. Later we will see more types.
960 .PP
961 It is the same for data. If you want to know the amount, look at the
962 averages. If you want to know the rate, look at the maximum.
963 Over time, they will grow apart more and more. In the last database
964 we have created, there are two archives that keep data per day. The
965 archive that keeps averages will show low numbers, the archive that
966 shows maxima will have higher numbers.
967 .PP
968 For my car this would translate in averages per day of 96/24=4 km/h
969 (as I travel about 94 kilometers on a day) during working days, and
970 maxima of 120 km/h (my top speed that I reach every day).
971 .PP
972 Big difference. Do not look at the second graph to estimate the
973 distances that I travel and do not look at the first graph to
974 estimate my speed. This will work if the samples are close together,
975 as they are in five minutes, but not if you average.
976 .PP
977 On some days, I go for a long ride. If I go across Europe and travel
978 for 12 hours, the first graph will rise to about 60 km/h. The second
979 one will show 180 km/h. This means that I traveled a distance of 60
980 km/h times 24 h = 1440 km. I did this with a higher speed and a
981 maximum around 180 km/h. However, it probably doesn't mean that I
982 traveled for 8 hours at a constant speed of 180 km/h!
983 .PP
984 This is a real example: go with the flow through Germany (fast!) and stop
985 a few times for gas and coffee. Drive slowly through Austria and the
986 Netherlands. Be careful in the mountains and villages. If you would
987 look at the graphs created from the five-minute averages you would
988 get a totally different picture. You would see the same values on the
989 average and maximum graphs (provided I measured every 300 seconds).
990 You would be able to see when I stopped, when I was in top gear, when
991 I drove over fast highways etc. The granularity of the data is much
992 higher, so you can see more. However, this takes 12 samples per hour,
993 or 288 values per day, so it would be a lot of data over a longer
994 period of time. Therefore we average it, eventually to one value per
995 day. From this one value, we cannot see much detail, of course.
996 .PP
997 Make sure you understand the last few paragraphs. There is no value
998 in only a line and a few axis, you need to know what they mean and
999 interpret the data in an appropriate way. This is true for all data.
1000 .PP
1001 The biggest mistake you can make is to use the collected data for
1002 something that it is not suitable for. You would be better off if
1003 you didn't have the graph at all.
1004 .Sh "Let's review what you now should know"
1005 .IX Subsection "Let's review what you now should know"
1006 You know how to create a database and can put data in it. You can get
1007 the numbers out again by creating an image, do math on the data from
1008 the database and view the result instead of the raw data.  You know
1009 about the difference between averages and maximum, and when to use
1010 which (or at least you should have an idea).
1011 .PP
1012 RRDtool can do more than what we have learned up to now. Before you
1013 continue with the rest of this doc, I recommend that you reread from
1014 the start and try some modifications on the examples. Make sure you
1015 fully understand everything. It will be worth the effort and helps
1016 you not only with the rest of this tutorial, but also in your day to day
1017 monitoring long after you read this introduction.
1018 .Sh "Data Source Types"
1019 .IX Subsection "Data Source Types"
1020 All right, you feel like continuing. Welcome back and get ready
1021 for an increased speed in the examples and explanations.
1022 .PP
1023 You know that in order to view a counter over time, you have to
1024 take two numbers and divide the difference of them between the
1025 time lapsed.  This makes sense for the examples I gave you but there
1026 are other possibilities.  For instance, I'm able to retrieve the
1027 temperature from my router in three places namely the inlet, the
1028 so called hot-spot and the exhaust.  These values are not counters.
1029 If I take the difference of the two samples and divide that by
1030 300 seconds I would be asking for the temperature change per second.
1031 Hopefully this is zero! If not, the computer room is probably on fire :)
1032 .PP
1033 So, what can we do?  We can tell RRDtool to store the values we measure
1034 directly as they are (this is not entirely true but close enough). The
1035 graphs we make will look much better, they will show a rather constant
1036 value. I know when the router is busy (it
1037 works \-> it uses more electricity \-> it generates more heat \-> the
1038 temperature rises). I know when the doors are left open (the room is
1039 air conditioned) \-> the warm air from the rest of the building flows into the
1040 computer room \-> the inlet temperature rises). Etc. The data type we
1041 use when creating the database before was counter, we now have a
1042 different data type and thus a different name for it. It is called
1043 \&\s-1GAUGE\s0. There are more such data types:
1044 .PP
1045 .Vb 4
1046 \& \- COUNTER   we already know this one
1047 \& \- GAUGE     we just learned this one
1048 \& \- DERIVE
1049 \& \- ABSOLUTE
1050 .Ve
1051 .PP
1052 The two additional types are \s-1DERIVE\s0 and \s-1ABSOLUTE\s0. Absolute can be used like
1053 counter with one difference: RRDtool assumes the counter is reset when
1054 it's read. That is: its delta is known without calculation by RRDtool
1055 whereas RRDtool needs to calculate it for the counter type.
1056 Example: our first example (12345, 12357, 12363, 12363) would read:
1057 unknown, 12, 6, 0. The rest of the calculations stay the same.
1058 The other one, derive, is like counter. Unlike counter, it can also
1059 decrease so it can have a negative delta. Again, the rest of the
1060 calculations stay the same.
1061 .PP
1062 Let's try them all:
1063 .PP
1064 .Vb 22
1065 \&   rrdtool create all.rrd \-\-start 978300900 \e
1066 \&            DS:a:COUNTER:600:U:U \e
1067 \&            DS:b:GAUGE:600:U:U \e
1068 \&            DS:c:DERIVE:600:U:U \e
1069 \&            DS:d:ABSOLUTE:600:U:U \e
1070 \&            RRA:AVERAGE:0.5:1:10
1071 \&   rrdtool update all.rrd \e
1072 \&            978301200:300:1:600:300    \e
1073 \&            978301500:600:3:1200:600   \e
1074 \&            978301800:900:5:1800:900   \e
1075 \&            978302100:1200:3:2400:1200 \e
1076 \&            978302400:1500:1:2400:1500 \e
1077 \&            978302700:1800:2:1800:1800 \e
1078 \&            978303000:2100:4:0:2100    \e
1079 \&            978303300:2400:6:600:2400  \e
1080 \&            978303600:2700:4:600:2700  \e
1081 \&            978303900:3000:2:1200:3000
1082 \&   rrdtool graph all1.png \-s 978300600 \-e 978304200 \-h 400 \e
1083 \&            DEF:linea=all.rrd:a:AVERAGE LINE3:linea#FF0000:"Line A" \e
1084 \&            DEF:lineb=all.rrd:b:AVERAGE LINE3:lineb#00FF00:"Line B" \e
1085 \&            DEF:linec=all.rrd:c:AVERAGE LINE3:linec#0000FF:"Line C" \e
1086 \&            DEF:lined=all.rrd:d:AVERAGE LINE3:lined#000000:"Line D"
1087 .Ve
1088 .Sh "RRDtool under the Microscope"
1089 .IX Subsection "RRDtool under the Microscope"
1090 .IP "\(bu" 2
1091 Line A is a \s-1COUNTER\s0 type, so it should continuously increment and RRDtool
1092 must calculate the differences. Also, RRDtool needs to divide the
1093 difference by the amount of time lapsed. This should end up as a
1094 straight line at 1 (the deltas are 300, the time is 300).
1095 .IP "\(bu" 2
1096 Line B is of type \s-1GAUGE\s0. These are \*(L"real\*(R" values so they should match
1097 what we put in: a sort of a wave.
1098 .IP "\(bu" 2
1099 Line C is of type \s-1DERIVE\s0. It should be a counter that can decrease. It does
1100 so between 2400 and 0, with 1800 in\-between.
1101 .IP "\(bu" 2
1102 Line D is of type \s-1ABSOLUTE\s0. This is like counter but it works on
1103 values without calculating the difference. The numbers are the same
1104 and as you can see (hopefully) this has a different result.
1105 .PP
1106 This translates in the following values, starting at 23:10 and ending
1107 at 00:10 the next day (where \*(L"u\*(R" means unknown/unplotted):
1108 .PP
1109 .Vb 4
1110 \& \- Line A:  u  u  1  1  1  1  1  1  1  1  1  u
1111 \& \- Line B:  u  1  3  5  3  1  2  4  6  4  2  u
1112 \& \- Line C:  u  u  2  2  2  0 \-2 \-6  2  0  2  u
1113 \& \- Line D:  u  1  2  3  4  5  6  7  8  9 10  u
1114 .Ve
1115 .PP
1116 If your \s-1PNG\s0 shows all this, you know you have entered the data correctly,
1117 the RRDtool executable is working properly, your viewer doesn't fool you,
1118 and you successfully entered the year 2000 :)
1119 .PP
1120 You could try the same example four times, each time with only one of
1121 the lines.
1122 .PP
1123 Let's go over the data again:
1124 .IP "\(bu" 2
1125 Line A: 300,600,900 and so on. The counter delta is a constant 300 and
1126 so is the time delta. A number divided by itself is always 1 (except
1127 when dividing by zero which is undefined/illegal).
1128 .Sp
1129 Why is it that the first point is unknown? We do know what we put into
1130 the database, right? True, But we didn't have a value to calculate the delta
1131 from, so we don't know where we started. It would be wrong to assume we
1132 started at zero so we don't!
1133 .IP "\(bu" 2
1134 Line B: There is nothing to calculate. The numbers are as they are.
1135 .IP "\(bu" 2
1136 Line C: Again, the start-out value is unknown. The same story is holds
1137 as for line A. In this case the deltas are not constant, therefore the line
1138 is not either. If we would put the same numbers in the database as we did for
1139 line A, we would have gotten the same line. Unlike type counter,
1140 this type can decrease and I hope to show you later on why
1141 this makes a difference.
1142 .IP "\(bu" 2
1143 Line D: Here the device calculates the deltas. Therefore we \s-1DO\s0 know the
1144 first delta and it is plotted. We had the same input as with line A, but
1145 the meaning of this input is different and thus the line is different.
1146 In this case the deltas increase each time with 300. The time delta
1147 stays at a constant 300 and therefore the division of the two gives
1148 increasing values.
1149 .Sh "Counter Wraps"
1150 .IX Subsection "Counter Wraps"
1151 There are a few more basics to show. Some important options are still to
1152 be covered and we haven't look at counter wraps yet. First the counter wrap:
1153 In our car we notice that the counter shows 999987. We travel 20 km and
1154 the counter should go to 1000007. Unfortunately, there are only six digits
1155 on our counter so it really shows 000007. If we would plot that on a type
1156 \&\s-1DERIVE\s0, it would mean that the counter was set back 999980 km. It wasn't,
1157 and there has to be some protection for this. This protection is only
1158 available for type \s-1COUNTER\s0 which should be used for this kind of counter
1159 anyways. How does it work? Type counter should never decrease and
1160 therefore RRDtool must assume it wrapped if it does decrease!
1161 If the delta is negative, this can be compensated for by adding the
1162 maximum value of the counter + 1. For our car this would be:
1163 .PP
1164 .Vb 1
1165 \& Delta = 7 \- 999987 = \-999980    (instead of 1000007\-999987=20)
1166 .Ve
1167 .PP
1168 .Vb 1
1169 \& Real delta = \-999980 + 999999 + 1 = 20
1170 .Ve
1171 .PP
1172 At the time of writing this document, RRDtool knows of counters that
1173 are either 32 bits or 64 bits of size. These counters can handle the
1174 following different values:
1175 .PP
1176 .Vb 2
1177 \& \- 32 bits: 0 ..           4294967295
1178 \& \- 64 bits: 0 .. 18446744073709551615
1179 .Ve
1180 .PP
1181 If these numbers look strange to you, you can view them in
1182 their hexadecimal form:
1183 .PP
1184 .Vb 2
1185 \& \- 32 bits: 0 ..         FFFFFFFF
1186 \& \- 64 bits: 0 .. FFFFFFFFFFFFFFFF
1187 .Ve
1188 .PP
1189 RRDtool handles both counters the same. If an overflow occurs and
1190 the delta would be negative, RRDtool first adds the maximum of a small
1191 counter + 1 to the delta. If the delta is still negative, it had to be
1192 the large counter that wrapped. Add the maximum possible value of the
1193 large counter + 1 and subtract the erroneously added small value.
1194 .PP
1195 There is a risk in this: suppose the large counter wrapped while adding
1196 a huge delta, it could happen, theoretically, that adding the smaller value
1197 would make the delta positive. In this unlikely case the results would
1198 not be correct. The increase should be nearly as high as the maximum
1199 counter value for that to happen, so chances are you would have several
1200 other problems as well and this particular problem would not even be
1201 worth thinking about. Even though, I did include an example, so you
1202 can judge for yourself.
1203 .PP
1204 The next section gives you some numerical examples for counter\-wraps.
1205 Try to do the calculations yourself or just believe me if your calculator
1206 can't handle the numbers :)
1207 .PP
1208 Correction numbers:
1209 .PP
1210 .Vb 3
1211 \& \- 32 bits: (4294967295 + 1) =                                4294967296
1212 \& \- 64 bits: (18446744073709551615 + 1)
1213 \&                                    \- correction1 = 18446744069414584320
1214 .Ve
1215 .PP
1216 .Vb 6
1217 \& Before:        4294967200
1218 \& Increase:                100
1219 \& Should become: 4294967300
1220 \& But really is:             4
1221 \& Delta:        \-4294967196
1222 \& Correction1:  \-4294967196 + 4294967296 = 100
1223 .Ve
1224 .PP
1225 .Vb 9
1226 \& Before:        18446744073709551000
1227 \& Increase:                             800
1228 \& Should become: 18446744073709551800
1229 \& But really is:                        184
1230 \& Delta:        \-18446744073709550816
1231 \& Correction1:  \-18446744073709550816
1232 \&                                + 4294967296 = \-18446744069414583520
1233 \& Correction2:  \-18446744069414583520
1234 \&                   + 18446744069414584320 = 800
1235 .Ve
1236 .PP
1237 .Vb 7
1238 \& Before:        18446744073709551615 ( maximum value )
1239 \& Increase:      18446744069414584320 ( absurd increase, minimum for
1240 \& Should become: 36893488143124135935             this example to work )
1241 \& But really is: 18446744069414584319
1242 \& Delta:                     \-4294967296
1243 \& Correction1:  \-4294967296 + 4294967296 = 0
1244 \& (not negative \-> no correction2)
1245 .Ve
1246 .PP
1247 .Vb 7
1248 \& Before:        18446744073709551615 ( maximum value )
1249 \& Increase:      18446744069414584319 ( one less increase )
1250 \& Should become: 36893488143124135934
1251 \& But really is: 18446744069414584318
1252 \& Delta:                     \-4294967297
1253 \& Correction1:  \-4294967297 + 4294967296 = \-1
1254 \& Correction2:  \-1 + 18446744069414584320 = 18446744069414584319
1255 .Ve
1256 .PP
1257 As you can see from the last two examples, you need strange numbers
1258 for RRDtool to fail (provided it's bug free of course), so this should
1259 not happen. However, \s-1SNMP\s0 or whatever method you choose to collect the
1260 data, might also report wrong numbers occasionally.  We can't prevent all
1261 errors, but there are some things we can do. The RRDtool \*(L"create\*(R" command
1262 takes two special parameters for this. They define
1263 the minimum and maximum allowed values. Until now, we used \*(L"U\*(R", meaning
1264 \&\*(L"unknown\*(R". If you provide values for one or both of them and if RRDtool
1265 receives data points that are outside these limits, it will ignore those
1266 values. For a thermometer in degrees Celsius, the absolute minimum is
1267 just under \-273. For my router, I can assume this minimum is much higher
1268 so I would set it to 10, where as the maximum temperature I would
1269 set to 80. Any higher and the device would be out of order.
1270 .PP
1271 For the speed of my car, I would never expect negative numbers and
1272 also I would not expect a speed  higher than 230. Anything else,
1273 and there must have been an error. Remember: the opposite is not true,
1274 if the numbers pass this check, it doesn't mean that they are
1275 correct. Always judge the graph with a healthy dose of suspicion if it
1276 seems weird to you.
1277 .Sh "Data Resampling"
1278 .IX Subsection "Data Resampling"
1279 One important feature of RRDtool has not been explained yet: it is
1280 virtually impossible to collect data and feed it into RRDtool on exact
1281 intervals. RRDtool therefore interpolates the data, so they are stored
1282 on exact intervals. If you do not know what this means or how it
1283 works, then here's the help you seek:
1284 .PP
1285 Suppose a counter increases by exactly one for every second. You want
1286 to measure it in 300 seconds intervals. You should retrieve values
1287 that are exactly 300 apart. However, due to various circumstances you
1288 are a few seconds late and the interval is 303. The delta will also be
1289 303 in that case. Obviously, RRDtool should not put 303 in the database
1290 and make you believe that the counter increased by 303 in 300 seconds.
1291 This is where RRDtool interpolates: it alters the 303 value as if it
1292 would have been stored earlier and it will be 300 in 300 seconds.
1293 Next time you are at exactly the right time. This means that the current
1294 interval is 297 seconds and also the counter increased by 297. Again,
1295 RRDtool interpolates and stores 300 as it should be.
1296 .PP
1297 .Vb 1
1298 \&      in the RRD                 in reality
1299 .Ve
1300 .PP
1301 .Vb 4
1302 \& time+000:   0 delta="U"   time+000:    0 delta="U"
1303 \& time+300: 300 delta=300   time+300:  300 delta=300
1304 \& time+600: 600 delta=300   time+603:  603 delta=303
1305 \& time+900: 900 delta=300   time+900:  900 delta=297
1306 .Ve
1307 .PP
1308 Let's create two identical databases. I've chosen the time range 920805000
1309 to 920805900 as this goes very well with the example numbers.
1310 .PP
1311 .Vb 4
1312 \&   rrdtool create seconds1.rrd   \e
1313 \&      \-\-start 920804700          \e
1314 \&      DS:seconds:COUNTER:600:U:U \e
1315 \&      RRA:AVERAGE:0.5:1:24
1316 .Ve
1317 .PP
1318 Make a copy
1319 .PP
1320 .Vb 3
1321 \&   for Unix: cp seconds1.rrd seconds2.rrd
1322 \&   for Dos:  copy seconds1.rrd seconds2.rrd
1323 \&   for vms:  how would I know :)
1324 .Ve
1325 .PP
1326 Put in some data
1327 .PP
1328 .Vb 4
1329 \&   rrdtool update seconds1.rrd \e
1330 \&      920805000:000 920805300:300 920805600:600 920805900:900
1331 \&   rrdtool update seconds2.rrd \e
1332 \&      920805000:000 920805300:300 920805603:603 920805900:900
1333 .Ve
1334 .PP
1335 Create output
1336 .PP
1337 .Vb 16
1338 \&   rrdtool graph seconds1.png                       \e
1339 \&      \-\-start 920804700 \-\-end 920806200             \e
1340 \&      \-\-height 200                                  \e
1341 \&      \-\-upper\-limit 1.05 \-\-lower\-limit 0.95 \-\-rigid \e
1342 \&      DEF:seconds=seconds1.rrd:seconds:AVERAGE      \e
1343 \&      CDEF:unknown=seconds,UN                       \e
1344 \&      LINE2:seconds#0000FF                          \e
1345 \&      AREA:unknown#FF0000
1346 \&   rrdtool graph seconds2.png                       \e
1347 \&      \-\-start 920804700 \-\-end 920806200             \e
1348 \&      \-\-height 200                                  \e
1349 \&      \-\-upper\-limit 1.05 \-\-lower\-limit 0.95 \-\-rigid \e
1350 \&      DEF:seconds=seconds2.rrd:seconds:AVERAGE      \e
1351 \&      CDEF:unknown=seconds,UN                       \e
1352 \&      LINE2:seconds#0000FF                          \e
1353 \&      AREA:unknown#FF0000
1354 .Ve
1355 .PP
1356 View both images together (add them to your index.html file)
1357 and compare. Both graphs should show the same, despite the
1358 input being different.
1359 .SH "WRAPUP"
1360 .IX Header "WRAPUP"
1361 It's time now to wrap up this tutorial. We covered all the basics for
1362 you to be able to work with RRDtool and to read the additional
1363 documentation available. There is plenty more to discover about
1364 RRDtool and you will find more and more uses for this package. You can
1365 easily create graphs using just the examples provided and using only
1366 RRDtool. You can also use one of the front ends to RRDtool that are
1367 available.
1368 .SH "MAILINGLIST"
1369 .IX Header "MAILINGLIST"
1370 Remember to subscribe to the RRDtool mailing list. Even if you are not
1371 answering to mails that come by, it helps both you and the rest of the
1372 users. A lot of the stuff that I know about \s-1MRTG\s0 (and therefore about
1373 RRDtool) I've learned while just reading the list without posting to
1374 it. I did not need to ask the basic questions as they are answered in
1375 the \s-1FAQ\s0 (read it!) and in various mails by other users. With
1376 thousands of users all over the world, there will always be people who
1377 ask questions that you can answer because you read this and other
1378 documentation and they didn't.
1379 .SH "SEE ALSO"
1380 .IX Header "SEE ALSO"
1381 The RRDtool manpages
1382 .SH "AUTHOR"
1383 .IX Header "AUTHOR"
1384 I hope you enjoyed the examples and their descriptions. If you do, help
1385 other people by pointing them to this document when they are asking
1386 basic questions. They will not only get their answers, but at the same
1387 time learn a whole lot more.
1388 .PP
1389 Alex van den Bogaerdt
1390 <alex@vandenbogaerdt.nl>