Home Engidea Home Circle

Mrtg Plot Ping Statistics Collection

The many of you that have an Internet connection often wonder about the quality of what is being provided. In this Blog I would like to discuss this topic and present to you a program that used together with MRTG can provide a good insight into the quality of your internet connection.

What does constitute the quality of an internet connection

When you buy your internet connection there are two raw measures that are being used.

For an ADSL line the downstream raw channel can be of 1.5MBits/sec and the upstream of 320KBits/sec, this may seem a lot but it is often the case that this number is just a number since the actual line capacity is much less due to "congestion"

So, when you are looking at line quality you have to make sure that the physical connection is good, and you can do this by looking at the physical error counters of your ADSL router (or of your HDSL router or of your fiber optical adapter), the number you read is usually some sort of errors on a given time frame. Ideally you should not have errors on the physical channel, but it is not a problem if you have some error (one every 10minutes is for most uses OK). As an example there is the statistics of my ADSL router, they show some errors, but not too much on 15 minutes.

hardware Statistics for my DASL router

Once you have a good physical line you start at looking at how many bytes actually pass trough the line. If in a given hour you can send trough the line a number of bytes that get close to the physical line capacity you are a happy Internet user !

The trouble begins when your downloading is slow and your internet activity is a pain. What is stopping your bytes to travel trough your physical line ?

The round trip time of a packet

The round trip time of a packet is the time that a packet takes to start from your machine, go to the destination and come back. Normally it is of the order of 50mseconds (for an ADSL connection) and this means that is you send something it arrives in much less than half a second. If you have a VoIP connection this is essential, otherwise your speech will arrive late compared to when you actually spoken.

If the round trip exceed two or three seconds not only your VoIP connection will suffer badly but also your browsing will suffer, from the time you click on a link three seconds will pass before the server reacts and send you a reply, you really do notice the time delay.

So, even if your physical link is good you be a slow surfer if your round trip time is more than 50msec, you need to measure this to be able to complain with your service provider ! As an example I show you the graph of my adsl connection where I plot the minimum and average round trip time with my nearest router.

Average and minimum Ping time with my nearest router

The blue line is the minimum round trip, the green part is the average, in milliseconds. The sampling time is one second so, in five minutes I take 300 samples and on them I calculate the value to display on MRTG.

The Lost packets

Lost packets are the worse thing that can happen to an internet connection (beside no connection at all). A packet lost results in a choppy VoIP voice, in retransmission for normal TCP connection, leading to a perceived performance drop that far exceeds a possible two or three second round trip delay for a packet.

Lost packets should really be zero all the time, if they are not (especially on an idle connection) then you really have a problem that should be investigated and reported.

Note that is your first jump to your nearest router is done using ATM technology it may be possible to have lost packets even with low latency, basically it means that as soon as the queue in the router exceed a small value, the router drops the cell with the result of a dropped IP packet. This should be reported and then fixed by the internet provider !
As an example I show the graph for my connection, do not look at the green part on the left, it is a plot before finishing the application, the real part starts from hours 11 onward and shows the maximum ping time in blue, the reference values are in milliseconds. The green part plots the lost packets (there is an issue here of plotting non uniform data on the same graph) and it is possible to see that I have few lost packets in five minutes. So, the connection is reasonably good.

Maximum Ping time with my nearest router and lost packets

You need to measure the values

If you have problems it is no good to call up the company providing the service and complain, unless you have some real figures to back up your claims. For this reason MRTG has been written, to provide reliable information on connection usages.

MRTG normally plots two values that are the number of bytes sent and received on a given line, it is a simple concept and is also simple to measure since most routers provides this value trough SNMP. But showing that little traffic pass trough your line is no good unless you can pinpoint why it is so. In the following example the graph shows that I really do not use my ADSL much, but since the round trip time is low (50ms) and I have basically no lost packets, then it is just that I do not do much browsing or P2P and spend most of my time working :-)

Traffic plot for my ADSL connection

To find out if you have lost packets or what is the maximum, average, minimum round trip time you could use the ping command. Ping is a nice program that (unless is firewalled) can measure the round trip and lost packets. But ping does not fit well with what Mrtg uses to measure up the data. The following example shows a ping run, you have the data, but from there you have to plot them !

When MRTG wants some data it may call an external program that should provide four lines as follows

Ping does not provides such lines and has no provision to do so. As far as I can google there is one other project that attempted to solve this issue but the result, although an improvement, I believe, is not satisfactory.

MRTG Ping Statistics generator

Mrtg ping probe does a quick sample of the line and then provides two results, there is another project called SmokePing that is able to provide feedback of ping times but I wanted something simple and pluggable with MRTG.

The main issue is that there should be a constant recording of ping times/lost packets and in parallel there is the data gathering of MRTG. So there should be a program that sends ping and gather results and another program that provides the results to MRTG.

The interface between the two programs is a shared memory segment, it is fast, easy, reliable and simple.

Usage is really simple, it is a matter compiling, starting the server and then configuring MRTG


Downloading mrtg-pingstst

The download includes a Makefile so you can compile mrtg-pinstat. The program is tested under Ubuntu Linux and it should run on any reasonably updated Linux machine. If you are ready, download the taz and expand it somewhere in your home directory.

tar -xzvf downloaded-file.taz

Compile mrtg-pingstat

Normally Ubuntu does not have support for a compiler, you have to add it, just type

sudo apt-get install build-essential

After the compiler and other stuff is installed just type

make

After a few seconds, you should see something like the following and end up with two executable called.

mrtg-pingstat-server
mrtg-pingstat-reader

Running the server

You should be able to run the server by just calling it and writing the desired ip address to ping. You can really write any end point that does reply to you but I find that what is most useful is to select as end point the next router after your ADSL CPE.
I am not going to write the ip of my access router, you could find it out if you wish. If somebody ask I will write some info on how to find out what is your next hop router.

mrtg-pingstat-server xxx.xxx.xxx.xxx

Note that since it sends raw ICMP packets the server should be run as root

Running MRTG

For details on how to start MRTG have a look at mrtg main site. The option I have chosen is to use crontab, this allows me to change the config script and have it automatically run the next time
NOTE it is really best if you get it working by testing it on the command line, I had to add env LANG=C in front of it to get it working and also had to set file permissions properly.
Once it works OK on the command line you can put into the crontab using crontab -e

*/5 * * * * <mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg --logging /var/log/mrtg.log

You also have to give the correct set of parameters into mrtg.cfg, here is my example

Target[telecom-ping]: `/home/damiano/mrtg/mrtg-pingstat-reader xxx.xxx.xxx.xxx `
MaxBytes[telecom-ping]: 1000
AbsMax[telecom-ping]: 2000
Title[telecom-ping]: Ping timings to telecom first router
Options[telecom-ping]: gauge, growright
YLegend[telecom-ping]: Max ping time (ms), Lost Pkt
ShortLegend[telecom-ping]:
Legend1[telecom-ping]: Lost pkt
Legend2[telecom-ping]: Maximum Round Trip Time in ms
Legend3[telecom-ping]: Lost Pkt
Legend4[telecom-ping]: Maximal 5 Minute Maximum Round Trip Time  in ms
LegendI[telecom-ping]: Lost Pkt:
LegendO[telecom-ping]: Max time (ms):

Note that the xxx.xxx.xxx.xxx is the same ip that you used to start the server !
By default the reported data is the Lost packets in five minutes and the Max round trip in five minutes.
It is possible to have other information, I am showing you next.

Parameters available for the reader and the server

This part is under construction, if you want to know what parameters are available now, look at the code.

Conclusion

I find that with this information I can successfully talk with my provider and show what kind of connection they are giving me, you can see my statistics at the following address. Bear in mind that this is just and ADSL, so, be kind, do not overload it :-)


Feedback welcomed

It would be nice if you could write a message giving a quick feedback
if you wish to be emailed back, please leave an address

   

Last Update 06/03/2007