.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "RRDTUTORIAL 1" .TH RRDTUTORIAL 1 "2022-04-14" "1.0.50" "RRDtool" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" rrdtutorial \- Alex van den Bogaerdt's RRDTool tutorial .SH "DESCRIPTION" .IX Header "DESCRIPTION" RRDTool is written by Tobias Oetiker with contributions from many people all around the world. This document is written by Alex van den Bogaerdt to help you understand what RRDTool is and what it can do for you. .PP The documentation provided with RRDTool can be too technical for some people. This tutorial is here to help you understand the basics of RRDTool. It should prepare you to read the documentation yourself. It also explains the general things about statistics with a focus on networking. .SH "TUTORIAL" .IX Header "TUTORIAL" .SS "Important" .IX Subsection "Important" Please don't skip ahead in this document! The first part of this document explains the basics and may be boring. But if you don't understand the basics, the examples will not be as meaningful to you. .SS "What is RRDTool ?" .IX Subsection "What is RRDTool ?" RRDTool refers to Round Robin Database tool. Round robin is a technique that works with a fixed amount of data, and a pointer to the current element. Think of a circle with some dots plotted on the edge, these dots are the places where data can be stored. Draw an arrow from the center of the circle to one of the dots, this is the pointer. When the current data is read or written, the pointer moves to the next element. As we are on a circle there is no beginning nor an end, you can go on and on. After a while, all the available places will be used and the process automatically reuses old locations. This way, the database will not grow in size and therefore requires no maintenance. RRDTool works with with Round Robin Databases (RRDs). It stores and retrieves data from them. .SS "What data can be put into an \s-1RRD\s0 ?" .IX Subsection "What data can be put into an RRD ?" You name it, it will probably fit. You should be able to measure some value at several points in time and provide this information to RRDTool. If you can do this, RRDTool will be able to store it. The values need to be numerical but don't have to be, as opposed to \s-1MRTG,\s0 integers. .PP Many examples talk about \s-1SNMP\s0 which is an acronym for Simple Network Management Protocol. \*(L"Simple\*(R" refers to the protocol \*(-- it does not mean it is simple to manage or monitor a network. After working your way through this document, you should know enough to be able to understand what people are talking about. For now, just realize that \s-1SNMP\s0 is a way to ask devices for the values of counters they keep. It is the value from those counters that are kept in the \s-1RRD.\s0 .SS "What can I do with this tool ?" .IX Subsection "What can I do with this tool ?" RRDTool originated from \s-1MRTG\s0 (Multi Router Traffic Grapher). \s-1MRTG\s0 started as a tiny little script for graphing the use of a connection to the Internet. \s-1MRTG\s0 evolved into a tool for graphing other data sources including temperature, speed, voltage, number of printouts and the like. Most likely you will start to use the RRDTool to store and process data collected via \s-1SNMP.\s0 The data will most likely be bytes (or bits) transfered from and to a network or a computer. RRDTool lets you create a database, store data in it, retrieve that data and create graphs in \s-1GIF\s0 format for display on a web browser. Those \s-1GIF\s0 images are dependent on the data you collected and could be, for instance, an overview of the average network usage, or the peaks that occurred. It can also be used to display tidal waves, solar radiation, power consumption, number of visitors at an exhibition, noise levels near an airport, temperature on your favorite holiday location, temperature in the fridge and whatever you imagination can come up with. You need a sensor to measure the data and be able to feed the numbers to RRDTool. .SS "What if I still have problems after reading this document ?" .IX Subsection "What if I still have problems after reading this document ?" First of all: read it again! You may have missed something. If you are unable to compile the sources and you have a fairly common \&\s-1OS,\s0 it will probably not be the fault of RRDTool. There may be precompiled versions around on the Internet. If they come from trusted sources, get one of those. If on the other hand the program works but does not give you the expected results, it will be a problem with configuring it. Review your configuration and compare it with the examples that follow. .PP There is a mailing list and an archive of it. Read the list for a few weeks and search the archive. It is considered rude to just ask a question without searching the archives: your problem may already have been solved for somebody else! This is true for most, if not all, mailing lists and not only for this particular list! Look in the documentation that came with RRDTool for the location and usage of the list. .PP I suggest you take a moment to subscribe to the mailing list right now by sending an email to with a subject of \*(L"subscribe\*(R". If you ever want to leave this list, you write an email to the same address but now with a subject of \*(L"unsubscribe\*(R". .SS "How will you help me ?" .IX Subsection "How will you help me ?" By giving you some detailed descriptions with detailed examples. It is assumed that following the instructions in the order presented will give you enough knowledge of RRDTool to experiment for yourself. If it doesn't work the first time, don't give up. Reread the stuff that you did understand, you may have missed something. By following the examples you get some hands-on experience and, even more important, some background information of how it works. .PP You will need to know something about hexadecimal numbers. If you don't then start with reading bin_dec_hex before you continue here. .SS "Your first Round Robin Database" .IX Subsection "Your first Round Robin Database" In my opinion the best way to learn something is to actually do it. Why not start right now? We will create a database, put some values in it and extract this data again. Your output should be the same as the output that is included in this document. .PP We will start with some easy stuff and compare a car with a router, or compare kilometers (miles if you wish) with bits and bytes. It's all the same: some number over some time. .PP Assume we have a device that transfers bytes to and from the Internet. This device keeps a counter that starts at zero when it is turned on, increasing with every byte that is transfered. This counter will have a maximum value, if that value is reached and an extra byte is counted, the counter starts all over at zero. This is the same as many counters in the world such as the mileage counter in a car. Most discussions about networking talk about bits per second so lets get used to that right away. Assume a byte is eight bits and start to think in bits not bytes. The counter, however, still counts bytes ! In the \s-1SNMP\s0 world most of the counters are 32 bits. That means they are counting from 0 to 4294967295. We will use these values in the examples. The device, when asked, returns the current value of the counter. We know the time that has passes since we last asked so we now know how many bytes have been transfered ***on average*** per second. This is not very hard to calculate. First in words, then in calculations: .IP "1." 3 Take the current counter, subtract the previous value from it. .IP "2." 3 Do the same with the current time and the previous time. .IP "3." 3 Divide the outcome of (1) by the outcome of (2), the result is the amount of bytes per second. Multiply by eight to get the number of bits per second (bps). .PP .Vb 1 \& bps = (counter_now \- counter_before) / (time_now \- time_before) * 8 .Ve .PP For some people it may help to translate this to a automobile example: Do not try this example, and if you do, don't blame me for the results. .PP People who are not used to think in kilometers per hour can translate most into miles per hour by dividing km by 1.6 (close enough). I will use the following abbreviations: .PP .Vb 6 \& M: meter \& KM: kilometer (= 1000 meters). \& H: hour \& S: second \& KM/H: kilometers per hour \& M/S: meters per second .Ve .PP You're driving a car. At 12:05 you read the counter in the dashboard and it tells you that the car has moved 12345 \s-1KM\s0 until that moment. At 12:10 you look again, it reads 12357 \s-1KM.\s0 This means you have traveled 12 \s-1KM\s0 in five minutes. A scientist would translate that into meters per second and this makes a nice comparison towards the problem of (bytes per five minutes) versus (bits per second). .PP We traveled 12 kilometers which is 12000 meters. We did that in five minutes which translates into 300 seconds. Our speed is 12000M / 300S equals 40 M/S. .PP We could also calculate the speed in \s-1KM/H: 12\s0 times five minutes is an hour so we have to multiply 12 \s-1KM\s0 by 12 to get 144 \s-1KM/H.\s0 For our native English speaking friends: that's 90 \s-1MPH\s0 so don't try this example at home or where I live :) .PP Remember: these numbers are averages only. There is no way to figure out from the numbers, if you drove at a constant speed. There is an example later on in this tutorial that explains this. .PP I hope you understand that there is no difference in calculating M/S or bps; only the way we collect the data is different. Even the K from kilo is the same as in networking terms k also means 1000. .PP We will now create a database where we can keep all these interesting numbers. The method used to start the program may differ slightly from \&\s-1OS\s0 to \s-1OS\s0 but I assume you can figure it out if it works different on your \s-1OS.\s0 Make sure you do not overwrite any file on your system when executing the following command and type the whole line as one long line (I had to split it for readability) and skip all of the '\e' characters. .PP .Vb 5 \& rrdtool create test.rrd \e \& \-\-start 920804400 \e \& DS:speed:COUNTER:600:U:U \e \& RRA:AVERAGE:0.5:1:24 \e \& RRA:AVERAGE:0.5:6:10 .Ve .PP (So enter: \f(CW\*(C`rrdtool create test.rrd \-\-start 920804400 DS ...\*(C'\fR) .SS "What has been created ?" .IX Subsection "What has been created ?" We created the round robin database called test (test.rrd) which starts at noon the day I started (7th of march, 1999) writing this document. It holds one data source (\s-1DS\s0) named \*(L"speed\*(R" that gets built from a counter. This counter is read every five minutes (default) In the same database two round robin archives (RRAs) are kept, one averages the data every time it is read (e.g. there's nothing to average) and keeps 24 samples (24 times 5 minutes is 2 hours). The other averages 6 values (half hour) and contains 10 of such averages (e.g. 5 hours) The remaining options will be discussed later on. .PP RRDTool works with special time stamps coming from the \s-1UNIX\s0 world. This time stamp is the number of seconds that passed since January 1st 1970 \s-1UTC.\s0 This time stamp is translated into local time and it will therefore look different for the different time zones. .PP Chances are that you are not in the same part of the world as I am. This means your time zone is different. In all examples where I talk about time, the hours may be wrong for you. This has little effect on the results of the examples, just correct the hours while reading. As an example: where I will see \*(L"12:05\*(R" the \s-1UK\s0 folks will see \*(L"11:05\*(R". .PP We now have to fill our database with some numbers. We'll pretend to have read the following numbers: .PP .Vb 10 \& 12:05 12345 KM \& 12:10 12357 KM \& 12:15 12363 KM \& 12:20 12363 KM \& 12:25 12363 KM \& 12:30 12373 KM \& 12:35 12383 KM \& 12:40 12393 KM \& 12:45 12399 KM \& 12:50 12405 KM \& 12:55 12411 KM \& 13:00 12415 KM \& 13:05 12420 KM \& 13:10 12422 KM \& 13:15 12423 KM .Ve .PP We fill the database as follows: .PP .Vb 5 \& rrdtool update test.rrd 920804700:12345 920805000:12357 920805300:12363 \& rrdtool update test.rrd 920805600:12363 920805900:12363 920806200:12373 \& rrdtool update test.rrd 920806500:12383 920806800:12393 920807100:12399 \& rrdtool update test.rrd 920807400:12405 920807700:12411 920808000:12415 \& rrdtool update test.rrd 920808300:12420 920808600:12422 920808900:12423 .Ve .PP This reads: update our test database with the following numbers .PP .Vb 2 \& time 920804700, value 12345 \& time 920805000, value 12357 .Ve .PP etcetera. .PP As you can see, it is possible to feed more than one value into the database in one command. I had to stop at three for readability but the real maximum is \s-1OS\s0 dependent. .PP We can now retrieve the data from our database using \*(L"rrdtool fetch\*(R": .PP .Vb 1 \& rrdtool fetch test.rrd AVERAGE \-\-start 920804400 \-\-end 920809200 .Ve .PP It should return the following output: .PP .Vb 1 \& speed \& \& 920804700: NaN \& 920805000: 0.04 \& 920805300: 0.02 \& 920805600: 0.00 \& 920805900: 0.00 \& 920806200: 0.03 \& 920806500: 0.03 \& 920806800: 0.03 \& 920807100: 0.02 \& 920807400: 0.02 \& 920807700: 0.02 \& 920808000: 0.01 \& 920808300: 0.02 \& 920808600: 0.01 \& 920808900: 0.00 \& 920809200: NaN .Ve .PP If it doesn't, something may be wrong. Perhaps your \s-1OS\s0 will print \&\*(L"NaN\*(R" in a different form. It represents \*(L"Not A Number\*(R". If your \s-1OS\s0 writes \*(L"U\*(R" or \*(L"\s-1UNKN\*(R"\s0 or something similar that's okay. If something else is wrong, it will probably be due to an error you made (assuming that my tutorial is correct of course :\-). In that case: delete the database and try again. .PP What this output represents will become clear in the rest of the tutorial. .SS "It is time to create some graphics" .IX Subsection "It is time to create some graphics" Try the following command: .PP .Vb 4 \& rrdtool graph speed.gif \e \& \-\-start 920804400 \-\-end 920808000 \e \& DEF:myspeed=test.rrd:speed:AVERAGE \e \& LINE2:myspeed#FF0000 .Ve .PP This will create speed.gif which starts at 12:00 and ends at 13:00. There is a definition of variable myspeed, it is the data from \s-1RRA\s0 \&\*(L"speed\*(R" out of database \*(L"test.rrd\*(R". The line drawn is 2 pixels high, and comes from variable myspeed. The color is red. You'll notice that the start of the graph is not at 12:00 but at 12:05 and this is because we have insufficient data to tell the average before that time. This will only happen when you miss some samples, this will not happen a lot, hopefully. .PP If this has worked: congratulations! If not, check what went wrong. .PP The colors are built up from red, green and blue. For each of the components, you specify how much to use in hexadecimal where 00 means not included and \s-1FF\s0 means fully included. The \*(L"color\*(R" white is a mixture of red, green and blue: \s-1FFFFFF\s0 The \*(L"color\*(R" black is all colors off: 000000 .PP .Vb 5 \& red #FF0000 \& green #00FF00 \& blue #0000FF \& magenta #FF00FF (mixed red with blue) \& gray #555555 (one third of all components) .Ve .PP The \s-1GIF\s0 you just created can be displayed using your favorite image viewer. Web browsers will display the \s-1GIF\s0 via the \s-1URL\s0 \&\*(L"file://the/path/to/speed.gif\*(R" .SS "Graphics with some math" .IX Subsection "Graphics with some math" When looking at the image, you notice that the horizontal axis is labeled 12:10, 12:20, 12:30, 12:40 and 12:50. The two remaining times (12:00 and 13:00) would not be displayed nicely so they are skipped. The vertical axis displays the range we entered. We provided kilometers and when divided by 300 seconds, we get very small numbers. To be exact, the first value was 12 (12357\-12345) and divided by 300 this makes 0.04, which is displayed by RRDTool as \*(L"40 m\*(R" meaning \*(L"40/1000\*(R". The \*(L"m\*(R" has nothing to do with meters, kilometers or millimeters! RRDTool doesn't know about all this, it just works with numbers and not with meters... .PP What we did wrong was that we should have measured in meters, this would have been (12357000\-12345000)/300 = 12000/300 = 40. .PP Let's correct that. We could recreate our database and store the correct data but there is a better way: do some calculations while creating the gif file ! .PP .Vb 6 \& rrdtool graph speed2.gif \e \& \-\-start 920804400 \-\-end 920808000 \e \& \-\-vertical\-label m/s \e \& DEF:myspeed=test.rrd:speed:AVERAGE \e \& CDEF:realspeed=myspeed,1000,* \e \& LINE2:realspeed#FF0000 .Ve .PP After viewing this \s-1GIF,\s0 you notice the \*(L"m\*(R" has disappeared. This it what the correct result would be. Also, a label has been added to the image. Apart from the things mentioned above, the \s-1GIF\s0 should be the same. .PP The calculations are in the \s-1CDEF\s0 part and are in Reverse Polish Notation (\*(L"\s-1RPN\*(R"\s0). What it says is: \*(L"take the data source myspeed and the number 1000; multiply those\*(R". Don't bother with \s-1RPN\s0 yet, it will be explained later on in more detail. Also, you may want to read my tutorial on CDEFs and Steve Rader's tutorial on \s-1RPN.\s0 But first finish this tutorial. .PP Hang on! If we can multiply values with 1000, it should also be possible to display kilometers per hour from the same data! .PP To change a value that is measured in meters per second: \-*\- Calculate meters per hour: value * 3600 \-*\- Calculate kilometers per hour: value / 1000 \-*\- Together this makes: value * (3600/1000) == value * 3.6 .PP In our example database we made a mistake and we need to compensate for this by multiplying with 1000. Applying that correction: \-*\- value * 3.6 *1000 == value * 3600 .PP Now let's create this \s-1GIF,\s0 and add some more magic ... .PP .Vb 10 \& rrdtool graph speed3.gif \e \& \-\-start 920804400 \-\-end 920808000 \e \& \-\-vertical\-label km/h \e \& DEF:myspeed=test.rrd:speed:AVERAGE \e \& "CDEF:kmh=myspeed,3600,*" \e \& CDEF:fast=kmh,100,GT,kmh,0,IF \e \& CDEF:good=kmh,100,GT,0,kmh,IF \e \& HRULE:100#0000FF:"Maximum allowed" \e \& AREA:good#00FF00:"Good speed" \e \& AREA:fast#FF0000:"Too fast" .Ve .PP This looks much better. Speed in \s-1KM/H\s0 and even an extra line with the maximum allowed speed (on the road I travel at). I also changed the colors used to display speed and changed it from a line into an area. .PP The calculations are more complex now. For the \*(L"good\*(R" speed they are: .PP .Vb 2 \& Check if kmh is greater than 100 ( kmh,100 ) GT \& If so, return 0, else kmh ((( kmh,100 ) GT ), 0, kmh) IF .Ve .PP For the other speed: .PP .Vb 2 \& Check if kmh is greater than 100 ( kmh,100 ) GT \& If so, return kmh, else return 0 ((( kmh,100) GT ), kmh, 0) IF .Ve .SS "Graphics Magic" .IX Subsection "Graphics Magic" I like to believe there are virtually no limits to how RRDTool graph can manipulate data. I will not explain how it works, but look at the following \s-1GIF:\s0 .PP .Vb 12 \& rrdtool graph speed4.gif \e \& \-\-start 920804400 \-\-end 920808000 \e \& \-\-vertical\-label km/h \e \& DEF:myspeed=test.rrd:speed:AVERAGE \e \& "CDEF:kmh=myspeed,3600,*" \e \& CDEF:fast=kmh,100,GT,100,0,IF \e \& CDEF:over=kmh,100,GT,kmh,100,\-,0,IF \e \& CDEF:good=kmh,100,GT,0,kmh,IF \e \& HRULE:100#0000FF:"Maximum allowed" \e \& AREA:good#00FF00:"Good speed" \e \& AREA:fast#550000:"Too fast" \e \& STACK:over#FF0000:"Over speed" .Ve .PP Let's create a quick and dirty \s-1HTML\s0 page to view three GIFs: .PP .Vb 7 \& Speed \& Speed in meters per second \&
\& Speed in kilometers per hour \&
\& Traveled too fast? \& .Ve .PP Name the file \*(L"speed.html\*(R" or similar, and view it. .PP Now, all you have to do is measure the values regularly and update the database. When you want to view the data, recreate the GIFs and make sure to refresh them in your browser. (Note: just clicking reload may not be enough; Netscape in particular has a problem doing so and you'll need to click reload while pressing the shift key). .SS "Updates in Reality" .IX Subsection "Updates in Reality" We've already used the \*(L"update\*(R" command: it took one or more parameters in the form of \*(L"