You had definitely came across a situation when your internet connection was down for a while. It usually happens in the most critical moment when you're in the middle of something important. I was asking myself how often this kind of internet connection outage happens when I am not using the internet at the moment. I decided to create a long-term stats of the internet stability to have something as a solid proof when complaining to my ISP. And it's also interesting to know how reliable is my ISP compared to the others.
To find out the moment of the connection outage the link must be tested each few minutes. This is perfect job for headless Raspberry PI connected to your local network. By "testing the link" is meant that the latency and packet loss will be measured between your network and some remote server. As a remote server can be chosen any reliable service like Google, Facebook, Twitter or better some of your remote servers.
I found a perfect ready to use tool named SmokePing that comes pre-bundled with the Raspbian linux. It does exactly what we need – it monitors the network latency and plots all the results into charts. SmokePing consists of a background daemon process which organizes the latency measurements and a CGI script which presents charts via web browser.
SmokePing installation and setup
All commands in this tutorial will be run as root
Install SmokePing with all its dependencies
apt-get install smokeping
After installation you can find all important config files in
/etc/smokeping/config.d/ directory. Detailed documentation of the config options can be found at the SmokePing website.
At this point you may consider editing the general settings like your name, email, host in the
/etc/smokeping/config.d/General, but this is not the point of this tutorial.
The most important thing is to configure probes – i. e. methods that will SmokePing use to measure the network latency. This tool supports a bunch of protocols to probe network connection (e. g. ICMP ECHO, DNS, HTTP, FTP, SSH). We will stick to the simplest one –
ICMP ECHO (common ping command that measures packet round-trip time).
*** Probes *** + FPing binary = /usr/bin/fping step = 300 # repeat each 5 minutes pings = 10 # send 10 ICMP packets
Next thing that needs to be configured is list of target remote servers. Edit the file
/etc/smokeping/config.d/Targets. Example config could look like this:
*** Targets *** probe = FPing menu = Top title = Raspberry Pi Internet Connection Monitor + Local menu = LAN title = LAN ++ router title = 192.168.0.1 menu = router host = 192.168.0.1 + Internet menu = Internet title = Internet Access (Ping) ++ Google title = Google menu = Google host = www.google.com ++ FB title = Facebook menu = Facebook host = www.facebook.com
You can replace target hosts with any other of your choice. I also added one host from my local network (my router gateway) to be able to distinguish between local network failures and internet connection failure.
Now it's everything set up and ready for starting the SmokePing daemon with the updated configuration:
service smokeping restart
After a couple of minutes you should see first results in the web front-end. Open your browser and load
http://[raspberry]/smokeping/smokeping.cgi. You should see similar website with latency charts.
Extending SD card lifetime
Smokeping uses RRDTool as internal database for measured data. And since the monitoring is continuous process it writes a new data to SD card every few minutes. That can contribute to SD card wear out pretty significantly. To avoid this issue I recommend to read another article about moving RRDTool data to volatile memory and extending your SD card lifetime Persistent RAM disk – extending SD card lifetime