Code

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