MRTG and RRDTool ================ Notes: ------ * Commands preceded with "$" imply that you should execute the command as a general user - not as root. * Commands preceded with "#" imply that you should be working as root. * Commands with more specific command lines (e.g. "GW-RTR>" or "mysql>") imply that you are executing commands on remote equipment, or within another program. * If a command line ends with "\" this indicates that the command continues on the next line and you should treat this as a single line. Exercises Part I ================ 0. Log in to your PC/VM or open a terminal window as the sysadm user. 1. Install MRTG --------------- We will install MRTG and graph input/output data for the network interfaces on our classroom routers - i.e. how much traffic is flowing across the router. $ sudo apt-get install mrtg When asked whether the file should be owned and readable only by root choose "" as it does need to be readable by RRDTool later on. 2. Create the /etc/mrtg directory --------------------------------- $ sudo mkdir /etc/mrtg 3. SNMP RO Community string: "NetManage" ---------------------------------------- You will need this information later. 4. Find the IP and Name of the Device ------------------------------------- You will do this exercises against your router. So, name and IP is name: rtrX.ws.nsrc.org IP: 10.10.X.254 So, for Group 3 the information would be: name: rtr3.ws.nsrc.org IP: 10.10.3.254 You need this information for step 5 (below). 5. Run cfgmaker (the command below all on one line!) ---------------------------------------------------- Let's become the root user at this point: $ sudo bash You are now root and your prompt should have a "#" at the end to indicate this. # mkdir -p /var/www/mrtg # /usr/bin/cfgmaker --output=/etc/mrtg/device.mrtg --global 'workdir: /var/www/mrtg' --global \ 'options[_]: growright,bits' NetManage@10.10.X.254 View the mrtg configuration file created by cfgmaker, you can make changes and see the results, if you want (/etc/mrtg/device.mrtg). For now, however, leave the file as it is. 6. Use indexmaker to create HTML files (all on one line!) --------------------------------------------------------- # /usr/bin/indexmaker --output=/var/www/mrtg/device.html /etc/mrtg/device.mrtg 7. Run MRTG command. Do this THREE TIMES! Really, THREE TIMES ------------------------------------------------------------- # LANG=C /usr/bin/mrtg /etc/mrtg/device.mrtg NOTE: Ubuntu/Debian will probably complain about LANG at this point. If this is so, just run the command above as: # "LANG=C /usr/bin/mrtg /etc/mrtg/device.mrtg" 8. Put the above command in a script ------------------------------------ # echo 'LANG=C /usr/bin/mrtg /etc/mrtg/device.mrtg' >/etc/mrtg/mrtgscript Make the script executable: # chmod +x /etc/mrtg/mrtgscript 9. Edit the crontab and insert the command to be run every 5 minutes --------------------------------------------------------------------- # crontab -e add: 0-59/5 * * * * /etc/mrtg/mrtgscript Save the file and exit. 10. Load the browser through webserver --------------------------------------- View the MRTG output in a browers. Point to your PC (pc1 through pc26): http://pcX.ws.nsrc.org/mrtg/device.html You will not see any results for a while - up to 10 minutes. At that point your graph should be moving. RRDTool -------- 1. Install the Required Pieces ------------------------------ # apt-get install rrdtool # apt-get install librrdp-perl # apt-get install librrds-perl Or, you could just type: # apt-get install rrdtool librrdp-perl librrds-perl This may take a while. 2. Add in your MRTG Configuration file -------------------------------------- # vi /etc/mrtg/device.mrtg Look for the following near the top of the file: # for Debian WorkDir: /var/www/mrtg Add a line just below the "WorkDir" line that reads: LogFormat: rrdtool Exit and save the file. Force quick, initial creation of the rrd files in /var/www/mrtg: # /etc/mrtg/mrtgscript Look at /var/www/mrtg and notice that there are now files named *.rrd: # ls /var/www/mrtg But what about graphs? 3. Install mrtg-rrd ------------------- # apt-get install mrtg-rrd # cd /usr/lib/cgi-bin # ln -s mrtg-rrd.cgi 14all.cgi 4. Run indexmaker again ------------------------ # /usr/bin/indexmaker --output=/var/www/mrtg/device.html /etc/mrtg/device.mrtg 5. Create /etc/mrtg-rrd.conf ---------------------------- # echo '/etc/mrtg/device.mrtg' >/etc/mrtg-rrd.conf 4. Make /var/www/mrtg writeable for the Web server --------------------------------------------------- # chown www-data /var/www/mrtg 5. Remove the old PNG files for the MRTG graphs ----------------------------------------------- # rm /var/www/mrtg/10.10*.png 6. Look at the webpage (http://pcX.ws.nsrc.org/mrtg/device.html) again ---------------------------------------------------------------------- You now have links to the graphs. Click on each one to see the new graphs. They look different, but contain the same information. Graphs are generated dynamically using RRD vs. being stored as separate PNG files every five minutes. You can adjust the look of pages, text on the pages, etc. by hand-editing the various files if you wish, but it is rather tedious... /etc/mrtg/device.mrtg /var/www/mrtg/device.html etc.