| 1 | MRTG and RRDTool |
|---|
| 2 | ================ |
|---|
| 3 | |
|---|
| 4 | Notes: |
|---|
| 5 | ------ |
|---|
| 6 | * Commands preceded with "$" imply that you should execute the command as |
|---|
| 7 | a general user - not as root. |
|---|
| 8 | * Commands preceded with "#" imply that you should be working as root. |
|---|
| 9 | * Commands with more specific command lines (e.g. "GW-RTR>" or "mysql>") |
|---|
| 10 | imply that you are executing commands on remote equipment, or within |
|---|
| 11 | another program. |
|---|
| 12 | * If a command line ends with "\" this indicates that the command continues |
|---|
| 13 | on the next line and you should treat this as a single line. |
|---|
| 14 | |
|---|
| 15 | Exercises Part I |
|---|
| 16 | ================ |
|---|
| 17 | |
|---|
| 18 | 0. Log in to your PC/VM or open a terminal window as the sysadm user. |
|---|
| 19 | |
|---|
| 20 | 1. Install MRTG |
|---|
| 21 | --------------- |
|---|
| 22 | |
|---|
| 23 | We will install MRTG and graph input/output data for the network interfaces on our classroom |
|---|
| 24 | routers - i.e. how much traffic is flowing across the router. |
|---|
| 25 | |
|---|
| 26 | $ sudo apt-get install mrtg |
|---|
| 27 | |
|---|
| 28 | When asked whether the file should be owned and readable only by root choose "<No>" as it |
|---|
| 29 | does need to be readable by RRDTool later on. |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | 2. Create the /etc/mrtg directory |
|---|
| 33 | --------------------------------- |
|---|
| 34 | |
|---|
| 35 | $ sudo mkdir /etc/mrtg |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | 3. SNMP RO Community string: "NetManage" |
|---|
| 39 | ---------------------------------------- |
|---|
| 40 | |
|---|
| 41 | You will need this information later. |
|---|
| 42 | |
|---|
| 43 | 4. Find the IP and Name of the Device |
|---|
| 44 | ------------------------------------- |
|---|
| 45 | |
|---|
| 46 | You will do this exercises against your router. So, name and IP is |
|---|
| 47 | |
|---|
| 48 | name: rtrX.ws.nsrc.org |
|---|
| 49 | IP: 10.10.X.254 |
|---|
| 50 | |
|---|
| 51 | So, for Group 3 the information would be: |
|---|
| 52 | |
|---|
| 53 | name: rtr3.ws.nsrc.org |
|---|
| 54 | IP: 10.10.3.254 |
|---|
| 55 | |
|---|
| 56 | You need this information for step 5 (below). |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | 5. Run cfgmaker (the command below all on one line!) |
|---|
| 60 | ---------------------------------------------------- |
|---|
| 61 | |
|---|
| 62 | Let's become the root user at this point: |
|---|
| 63 | |
|---|
| 64 | $ sudo bash |
|---|
| 65 | |
|---|
| 66 | You are now root and your prompt should have a "#" at the end to indicate this. |
|---|
| 67 | |
|---|
| 68 | # mkdir -p /var/www/mrtg |
|---|
| 69 | |
|---|
| 70 | # /usr/bin/cfgmaker --output=/etc/mrtg/device.mrtg --global 'workdir: /var/www/mrtg' --global \ |
|---|
| 71 | 'options[_]: growright,bits' NetManage@10.10.X.254 |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | View the mrtg configuration file created by cfgmaker, you can make changes and see the results, |
|---|
| 75 | if you want (/etc/mrtg/device.mrtg). For now, however, leave the file as it is. |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | 6. Use indexmaker to create HTML files (all on one line!) |
|---|
| 79 | --------------------------------------------------------- |
|---|
| 80 | |
|---|
| 81 | # /usr/bin/indexmaker --output=/var/www/mrtg/device.html /etc/mrtg/device.mrtg |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | 7. Run MRTG command. Do this THREE TIMES! Really, THREE TIMES |
|---|
| 85 | ------------------------------------------------------------- |
|---|
| 86 | |
|---|
| 87 | # LANG=C /usr/bin/mrtg /etc/mrtg/device.mrtg |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | NOTE: Ubuntu/Debian will probably complain about LANG at this point. If this is so, just run |
|---|
| 91 | the command above as: |
|---|
| 92 | |
|---|
| 93 | # "LANG=C /usr/bin/mrtg /etc/mrtg/device.mrtg" |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | 8. Put the above command in a script |
|---|
| 97 | ------------------------------------ |
|---|
| 98 | |
|---|
| 99 | # echo 'LANG=C /usr/bin/mrtg /etc/mrtg/device.mrtg' >/etc/mrtg/mrtgscript |
|---|
| 100 | |
|---|
| 101 | Make the script executable: |
|---|
| 102 | |
|---|
| 103 | # chmod +x /etc/mrtg/mrtgscript |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | 9. Edit the crontab and insert the command to be run every 5 minutes |
|---|
| 107 | --------------------------------------------------------------------- |
|---|
| 108 | |
|---|
| 109 | # crontab -e |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | add: |
|---|
| 113 | |
|---|
| 114 | 0-59/5 * * * * /etc/mrtg/mrtgscript |
|---|
| 115 | |
|---|
| 116 | Save the file and exit. |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | 10. Load the browser through webserver |
|---|
| 120 | --------------------------------------- |
|---|
| 121 | |
|---|
| 122 | View the MRTG output in a browers. Point to your PC (pc1 through pc26): |
|---|
| 123 | |
|---|
| 124 | http://pcX.ws.nsrc.org/mrtg/device.html |
|---|
| 125 | |
|---|
| 126 | You will not see any results for a while - up to 10 minutes. At that point your |
|---|
| 127 | graph should be moving. |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | RRDTool |
|---|
| 133 | -------- |
|---|
| 134 | |
|---|
| 135 | 1. Install the Required Pieces |
|---|
| 136 | ------------------------------ |
|---|
| 137 | |
|---|
| 138 | # apt-get install rrdtool |
|---|
| 139 | # apt-get install librrdp-perl |
|---|
| 140 | # apt-get install librrds-perl |
|---|
| 141 | |
|---|
| 142 | Or, you could just type: |
|---|
| 143 | |
|---|
| 144 | # apt-get install rrdtool librrdp-perl librrds-perl |
|---|
| 145 | |
|---|
| 146 | This may take a while. |
|---|
| 147 | |
|---|
| 148 | 2. Add in your MRTG Configuration file |
|---|
| 149 | -------------------------------------- |
|---|
| 150 | |
|---|
| 151 | # editor /etc/mrtg/device.mrtg |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | Look for the following near the top of the file: |
|---|
| 155 | |
|---|
| 156 | # for Debian |
|---|
| 157 | WorkDir: /var/www/mrtg |
|---|
| 158 | |
|---|
| 159 | Add a line just below the "WorkDir" line that reads: |
|---|
| 160 | |
|---|
| 161 | LogFormat: rrdtool |
|---|
| 162 | |
|---|
| 163 | Exit and save the file. |
|---|
| 164 | |
|---|
| 165 | Force quick, initial creation of the rrd files in /var/www/mrtg: |
|---|
| 166 | |
|---|
| 167 | # /etc/mrtg/mrtgscript |
|---|
| 168 | |
|---|
| 169 | Look at /var/www/mrtg and notice that there are now files named *.rrd: |
|---|
| 170 | |
|---|
| 171 | # ls /var/www/mrtg |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | But what about graphs? |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | 3. Install mrtg-rrd |
|---|
| 178 | ------------------- |
|---|
| 179 | |
|---|
| 180 | # apt-get install mrtg-rrd |
|---|
| 181 | # cd /usr/lib/cgi-bin |
|---|
| 182 | # ln -s mrtg-rrd.cgi 14all.cgi |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | 4. Run indexmaker again |
|---|
| 186 | ------------------------ |
|---|
| 187 | |
|---|
| 188 | # /usr/bin/indexmaker --output=/var/www/mrtg/device.html /etc/mrtg/device.mrtg |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | 5. Create /etc/mrtg-rrd.conf |
|---|
| 192 | ---------------------------- |
|---|
| 193 | |
|---|
| 194 | # echo '/etc/mrtg/device.mrtg' >/etc/mrtg-rrd.conf |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | 4. Make /var/www/mrtg writeable for the Web server |
|---|
| 198 | --------------------------------------------------- |
|---|
| 199 | |
|---|
| 200 | # chown www-data /var/www/mrtg |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | 5. Remove the old PNG files for the MRTG graphs |
|---|
| 204 | ----------------------------------------------- |
|---|
| 205 | |
|---|
| 206 | # rm /var/www/mrtg/10.10*.png |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | 6. Look at the webpage (http://pcX.ws.nsrc.org/mrtg/device.html) again |
|---|
| 210 | ---------------------------------------------------------------------- |
|---|
| 211 | |
|---|
| 212 | You now have links to the graphs. Click on each one to see the new graphs. They look |
|---|
| 213 | different, but contain the same information. |
|---|
| 214 | |
|---|
| 215 | Graphs are generated dynamically using RRD vs. being stored as separate PNG files every |
|---|
| 216 | five minutes. |
|---|
| 217 | |
|---|
| 218 | You can adjust the look of pages, text on the pages, etc. by hand-editing the various files |
|---|
| 219 | if you wish, but it is rather tedious... |
|---|
| 220 | |
|---|
| 221 | /etc/mrtg/device.mrtg |
|---|
| 222 | /var/www/mrtg/device.html |
|---|
| 223 | |
|---|
| 224 | etc. |
|---|