MRTS – MRTG RRDtool Total Statistics
March 16th, 2006 — bjouThis little guide is not supposed to be an introduction to SNMP, RRDtool or MRTG though I will give a very tiny look into these programs. The true intension of this tutorial is a properly configured MRTS that, of course, goes along with a correct installation of MRTG, RRDtool and SNMP. So most of the time we will have to configure these three programs. Moreover this tutorial is based on a FreeBSD system, i am running 6-STABLE. I presume that you have Apache installed and configured properly for the use with PHP. If not, do so! I won’t explain that here. The following chapter will give a short overview over the programs we need for setting up MRTS. The programm summaries are the ones that can be found on the corresponding official websites along with other detailed information on that specific program. So let’s get started.
Overview
- So what is MRTS anyway?
- Website: http://apt-get.dk/mrts
- Description: MRTS is short for “MRTG RRDtool Total Statistics”. It is a PHP script written by Thor Dreier that uses “MRTG and RRDtool to sum up total traffic monthly and yearly”. But why making words, if you can see the full power of MRTS in some examples: http://mrts.domainnet.dk Just click on any device and MRTS will show you the traffic-graphs and some statistics on how much traffic you have made during the actual/last months/year.
OK, now we know what MRTS does, but…
- What is MRTG?
- Website: http://oss.oetiker.ch/mrtg/
- Description: “The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing graphical images which provide a LIVE visual representation of this traffic. [...] MRTG is based on Perl and C and works under UNIX and Windows NT.” Again, we want to see some results on that, to see its power. So just take a look at http://www.stat.ee.ethz.ch/mrtg and pick a device. I think you’ll be satisfied. MRTG goes along alone very well, so if the examples, you have just seen, is everything you want, just install MRTG and you are free to go. (Note: You must NOT use the mrtg.cfg we will configure below. Just skip the Logformat: rrdtool command for MRTG standalone setup). I, for my part, was not fully satisfied with MRTG, because I wanted my router/server to show me detailed traffic summaries over the last months/year. And that’s where MRTS comes into play, because MRTS sums up this traffic using MRTG and RRDtool.
- What is RRDtool?
- Website: http://oss.oetiker.ch/rrdtool/
- Description: “If you know MRTG, you can think of RRDtool as a reimplementation of MRTGs graphing and logging features. Magnitudes faster and more flexible than you ever thought possible. RRD is the Acronym for Round Robin Database. RRD is a system to store and display time-series data (i.e. network bandwidth, machine-room temperature, server load average). It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it.” RRDtool allows you to almost log everything and convert it into nice impressive graphs. Take a look at http://oss.oetiker.ch/rrdtool/gallery/index.en.html for some examples.
As MRTG needs the Simple Network Management Protocol (SNMP) to work properly, we will take a short look on what this does:
- What is SNMP?
- Website: http://net-snmp.sourceforge.net/
- Description: “SNMP is an application-layer protocol that facilitates the exchange of management information between network devices. It is part of the Transmission Control Protocol/Internet Protocol (TCP/IP) protocol suite. SNMP enables network administrators to manage network performance, find and solve network problems, and plan for network growth.” For our plans, we need to install net-SNMP (formerly known as ucd-SNMP) that consists of various tools relating to SNMP.
So, enough explanations, let’s get to work!
Installing and Compiling
-
First thing to do is to check, which of the above mentioned packages you already have installed. No idea? Well, then you should do a simple
ls /var/db/pkg or pkg_infowhich lists the packages, you have installed using the FreeBSD ports. If you don’t know what the FreeBSD ports are, then you probably won’t have to read on, as some basics really are required in this tutorial
Net-SNMP: /usr/ports/net-mgmt/net-snmp
MRTG: /usr/ports/net-mgmt/mrtg
RRDtool: /usr/ports/net/rrdtool
Some of these programs depend on various libraries (e.g. zlib, libpng, GD), but that’s the good thing: The port-install-mechanism will automatically check, if you have them or not and it will install them, if needed. Do a
make && make install && make clean
in the corresponding port directories to install that specific port.
Now it could take a while until all ports are compiled.
Configuring
-
Alright, as far as I see, we are done compiling
- Configuration of net-SNMP
- Type y for configuring “the information returned in the system MIB group”
- syslocation is a string of the location of your server, e.g. “my room”, syscontact is you.
- Type y for setting “the value of the sysServices.0 OID”
- The following questions should be answered with “1″ (yes) or “0″ (no). Commonly it is “0″ for repeater and bridge and “1″ for IP, TCP, SMTP
- Type y for configuring “the agent’s access control”. Then answer the following three questions (read-write user based access, read-only user based access, read-write community access) with n. Answer the next one (read-only community access) with y. You will be asked for a community name. Invent one or take the default: public (NOT RECOMMENDED!) The network to accept this community from should be the loopback (127.0.0.1) or something like 192.168.100.0/24 for example. 0.0.0.0/0 will give anyone access. Don’t use this! Hit [return] for “no restriction” in the next question. Then you are finished, don’t do another community line. The rest can all be answered with n.
- Finally send the SNMPdeamon a Hangup Signal for re-reading the configuration, if SNMP was running while configuring:
ps faux | grep snmpdtells you the PID to sendkill -HUP theSnmpdPidto.
Create a snmpd.conf with
snmpconf -i -g basic_setup
This will start a walktrough asking you some questions about your system. The book “Absolute BSD” (“FreeBSD de Luxe” in Germany) explains in detail, how to properly set up net-SNMP. I’m gonna make it short:
The snmpd.conf is now stored in /usr/local/share/snmp/. Move it to /usr/local/etc/snmp/snmp.conf (Note: This Setup was very basic and does by far not show the power of net-SNMP. But for our purpose that is all we need right now. You should probably read some literature about it and do a better configuration afterwards. Read http://net-snmp.sourceforge.net/tutorial/tutorial-5/mrtg/index.html for more information on how to set up MRTG to monitor disk-space, CPU-load and so on…)
OK, next step is to start the services, i.e. snmp and mrtg. You can do this via the start scripts in
/usr/local/etc/rc.d/
Speaking of start-scripts, make one for MRTG (mrtg.sh) if there is non in the directory, we’ll need it later. Of course, you only have to do this step, if the installation of MRTG does not have put an autostart script itsself into /usr/local/etc/rc.d/. When I installed it, this was not the case so I had to make my own.
#!/bin/sh
/usr/local/bin/mrtg --logging=/var/log/mrtg.log --pid-file=/var/run/mrtg.pid /etc/mrtg.cfg
Now start snmpd (e.g. ‘/usr/local/etc/rc.d/snmpd.sh start’). Check if the processess are running!
PS: If you are using one of the lastest FreeBSD Releases (5.x and up) you are advised to start the deamons via /etc/rc.conf at boot-time. Consult some other Information source on how to use the rc-scripts.
- Configuration of MRTG
OK, snmpd is running, let’s configure MRTG. The binaries should be localted in /usr/local/bin. The “\” in the following command means, that this should be one line. Type
cfgmaker --global 'WorkDir: /usr/home/www/stats' --global 'Options[_]: growright' \
--output /etc/mrtg.cfg community@router.abc.xyz
where WorkDir is the directory, where the images and html pages should be placed (Note: Later on we will have no images and htmlpages in that directory, but one php-script (MRTS) and some *.rrd files containing the RRDtool data). It has to be visible to a webbrowser, of course. You can play with the arguments, this one should be the best for the first time, for detailed documentation check the website or your man-pages. output is the directory, where your config file will be placed. Replace community@router.abc.xyz with your specification, i.e. public@localhost. This should test your devices and have an output like this:
--base: Get Device Info on public@localhost:
--base: Vendor Id:
--base: Populating confcache
--snpo: confcache public@localhost: Descr rl0 --> 1
--snpo: confcache public@localhost: Descr lp0 --> 2
--snpo: confcache public@localhost: Descr ed1 --> 3
--snpo: confcache public@localhost: Descr lo0 --> 4
--snpo: confcache public@localhost: Descr tun0 --> 5
--snpo: confcache public@localhost: Ip 127.0.0.1 --> 4
--snpo: confcache public@localhost: Ip 192.168.100.100 --> 1
--snpo: confcache public@localhost: Ip 213.23.58.244 --> 5 [It's a dynamic IP, just for your notice
]
--snpo: confcache public@localhost: Type 6 --> 1
--snpo: confcache public@localhost: Type 34 --> 2
--snpo: confcache public@localhost: Type 6 --> 3 (duplicate)
--snpo: confcache public@localhost: Type 24 --> 4
--snpo: confcache public@localhost: Type 23 --> 5
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifSpeed
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Writing /etc/mrtg.cfg
If it does not do something similar like this, you did something wrong in configuring snmpd or snmpd is not running. So take a look at the output. What do you want to log? I wanted to log my internet-traffic, so i had to take device number 5 (device 4, i.e., is software-loopback, device 1 is internal traffic in your LAN). Open your newly configured /etc/mrtg.cfg and check it out. It needs some reconfiguration for our needs. First lines without a comment should be
WorkDir: /usr/home/www/stats/
Options[_]: growright
Logformat: rrdtool
RunAsDaemon: Yes
Interval: 5
PathAdd: /usr/local/bin/
IconDir: http://my.url.com/stats/icons/
I really suggest to read http://people.ee.ethz.ch/~oetiker/webtools/mrtg/reference.html for more and detailed information, though i am going to explain the commands above.
You already know the first two lines. The third one is very important. Without it, MRTG would create the images itsself without using RRDtool. But i like RRDtool images better
Furthermore you would have to do a cronjob for MRTG AND indexmaker, to create your corresponding html-files as well. With the Logformat command MRTG will save all its data in one file called ##device##.rrd where ##device## is i.e. localhost. Thanks to that file, we can use RRDtool to evaluate our graphs. RunAsDaemon is a very nice feature for avoiding a cronjob. After starting MRTG, it is being daemonized and not launched repeatedly (as it would have been with cron). MRTG will be active every 5 minutes. PathAdd is not always needed, but it can’t harm. It’s the path to your RRDtool binary and IconDir is the directory the icons are in, that came with the installation of MRTG (look for the icons in /usr/local/share/mrtg/) After these commands your devices are being listet. Comment those out that you do not want to log. I just wanted to log device #5. Should look something like this:
### Interface 5 >> Descr: 'tun0' | Name: '' | Ip: '213.23.58.171' | Eth: '' ###
Target[localhost_5]: 5:public@localhost:
SetEnv[localhost_5]: MRTG_INT_IP="213.23.58.171" MRTG_INT_DESCR="tun0"
MaxBytes[localhost_5]: 750000
Title[localhost_5]: Traffic Analysis
PageTop[localhost_5]: <H1>Internet Traffic Analysis</H1>
<TABLE>
<TR><TD>System:</TD> <TD>FreeBSD 6-STABLE in Bjou's Home in Karlsruhe City</TD></TR>
<TR><TD>Max Speed:</TD> <TD>Arcor-DSL 6 MBit</TD></TR>
</TABLE>
You are free to alter some values, I deleted some of them within the <TABLE></TABLE> because I didn’t find them very interesting. It will not affect your MRTS appearance anyway, but your MRTG output, if you want to make a standalone MRTG installation or if you want to use an “on-the-fly”-script as mrtg-rrd or 14all.cgi (which I also advise to take a look at, though you don’t need it). Maybe don’t alter anything before really getting started, you will know what you want to alter later, when you see the results (Note again: You won’t actually see the above strings in your MRTS output!). First line is the most important one: 5:public@localhost: 5 is your interface number mentioned above followed by community@router.abc.xyz. Thor Dreier explains on his MRTS website how to get the value for MaxBytes:
“In “MaxBytes” we have set how many bytes the device maximum can transfer:
(100Mbit * 1000000bit/Mbit / 8byte/bit = 12500000byte).”
So as I have a 1.5 MBit bandwidth, we’ll have to set: (6Mbit * 1000000bit/Mbit / 8byte/bit = 750000 byte)
Be sure to read Thor’s MRTS site properly for some additional information I did not mention here (especially if your are a Debian User).
What, you are still here? READ IT NOW! ![]()
OK, looks like we configured the mrtg.cfg well, so let’s start MRTG using our script above. You are getting error messages? No problem, this is normal the first time(s) you start MRTG. You maybe want to run MRTG under a certain user (running processes under root is not always the wisest decision)
therefore you will need the --user=mrtg_user --group=mrtg_group switches in your mrtg.sh startscript. It could be that there are some problems then, if mrtg_user does not have the rights it needs to access/write certain files. Try yourself, I won’t explain that here.
Having started MRTG, it should say “Daemonizing MRTG …” as a result. Check your logfile and your processes if it was successful.
- Configuration of RRDtool
RRDtool does not really need any further configuration, so I would say, we are almost done. Anyway, check if RRDtool
at least works. You can do this by taking a look at http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/tutorial/rrdtutorial.html
and doing this lesson at least until you got the first results and you are sure, RRDtool works.
- Configuration of MRTS itsself
Now comes the best part, the wonderful MRTS. Download from http://apt-get.dk/mrts/download/
(same files with different extension) and rename to *.php. Open the file and configure the following:
/* The directory where the rrd files are located */
$dir = ‘/usr/home/www/stats’;
/* List all devices that MRTS should’n display, */
$exclude = array(’secret’, ‘topsecret’);
/* RRDtool path – where is the the executable located */
$rrdcommand = ‘/usr/local/bin/rrdtool’;
The first path is exactly the MRTG WorkDir, second one explains itsself, last one is the path to your rrdtool executable. (Note:
rrdtool in the path listed above in not a folder, but the rrdtool binary!)
Well, that’s it. If your Apache is properly configured, give it a try. But first check, that you do not run your script in “safe mode php”.
If you server does this as standard, you have to put something like this in your httpd.conf:
<Directory “/path/to/mrts”>
php_admin_value safe_mode 0
<Directory>
Put the MRTS php script in /usr/home/www/stats/ and surf on it. And….. whoo-hoo, you are done! ![]()
May 25th, 2006 at 10:09 pm
Have you managed to use the PHP script with the latest version of RRDTool (1.2.xx)? I am running Cacti and version 1.2.12 of RRDTool and unfortunatly always get no data returned from the RRD’s.
Thanks
May 28th, 2006 at 12:04 pm
yes, running rrdtool 1.2.11 myself, not encountering any problems.
September 17th, 2006 at 11:30 pm
Using Cacti 0.8.6iB4
Had to modify line 424 I believe ($rrdcommand) to use ‘traffic_in’ and ‘traffic_out’ instead of ds0/ds1
$rrdcommand = “$rrdcommand graph – -v ‘Bytes/s’ -b 1024 -w 390 DEF:avgin=$name:traffic_in:AVERAGE AREA:avgin#00CC00:’Traffic in’ DEF:avgout=$name:traffic_out:AVERAGE LINE2:avgout#0000FF:’Traffic out’”;
Graphs are not displaying though. So its reading the data from the RRD files but RRDTools 1.2.15 is not generating graphs. They generate just fine in Cacti.
I have set
$rrdcommand = ‘c:/cacti/rrdtool’;
Any ideas on what I should look at to figure out why the d/w/m/y graphs are not displaying in MRTS?
December 2nd, 2006 at 8:06 am
Leggo ed imparo sul vostro luogo. grazie!
April 6th, 2007 at 7:06 pm
I want to filter out the data between 12AM and 8 AM for the purpose of totaling the data transferred. Those are my ISP’s happy hours. Is it possible in MRTS?
April 7th, 2007 at 9:56 am
I don’t think so
June 12th, 2007 at 11:27 am
It seems impossible to download the MRTS util
June 12th, 2007 at 4:40 pm
i’m missing it too …
June 29th, 2007 at 12:51 pm
mrts is at http://download.tsdn.dk/software/mrts/
August 16th, 2007 at 12:09 pm
How to config or setting RRDTool??
August 16th, 2007 at 9:53 pm
nothing special to configure there
October 13th, 2007 at 1:33 pm
Software Development Guide…
I couldn’t understand some parts of this article, but it sounds interesting…
December 19th, 2009 at 8:38 pm
Hi Guys there,
I am looking for great help….
does anybody provide me detail confinguration guide for the MRTG on windows 2008 R2