Code

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