ISP congestion monitoring with Raspberry Pi

The ISP I use at home is suffering from pretty bad congestion and the service has become barely usable during peak times. Despite multiple reports from other customers, they won’t admit that there is a problem, so it’s time to show them some data!

Screen Shot 2015-04-16 at 10.46.50 pm

I put together a really quick and hacky shell script that grabs a large-ish file from their own speedtest server (within their network) and logs the max download speed to a CSV file.

                              File: bwtest.sh                                                                   

#!/bin/sh
#script to test FTP download speed and log the result to a CSV

#set the path to download target file
TARGET="http://speedtest.amnet.net.au/speedtest/random2000x2000.jpg"

#set the path to local log file
LOGFILE="/home/pi/bandwidth-monitor/downloadlog"

#set the path to the CSV output file
CSVFILE="/home/pi/bandwidth-monitor/output.csv"

#timestamp formatting for record
TIMESTAMP=$(date +"%d/%m/%Y %H:%M:%S")

#This ugly thing returns and writes the last lines of the results to file
wget $TARGET /dev/null 2>&1 | tail -3 >> $LOGFILE

#Now just get the MB/s.. Pretty hacky..
RESULT=$(cat $LOGFILE | tail -c 12 | sed -e 's/(\(.*\))/\1/' | head -c-5)

#Write it to a CSV with timestamp
echo "$TIMESTAMP, $RESULT" >> $CSVFILE

#cleanup files, since the /dev/null bit didn't work..
#rm -rf test1*
rm -rf random*

echo "Record Saved at" $TIMESTAMP. Temp files deleted.

I was going to build some sort of charting functionality into this, to spit out a rendered graph image or serves a webpage that has a web chart, but if you google ‘graphing library linux’ you immediately find RRDtool, and then if you keep going, you find Smokepin. So now the same Raspberry Pi also runs Smokeping.

This can chart not only ICMP, but also FTP (though due to limitations in RRDtool, the unit of ‘ms’ is hardcoded).

Here’s what it looks like when an ISP fixes their congestion issues:

smokeping-rtt

Selecting the FTP chart will bring up something like the following:

Screen Shot 2015-04-17 at 12.18.44 pm

Smokeping is a great tool. Stable, light, and set-and-forget.
Here’s my Probes config:

File: /etc/smokeping/config.d/Probes
*** Probes ***

+ FPing

binary = /usr/bin/fping

+FTPtransfer

destfile = /home/pi/bandwidth-monitor/test1MB.dat
forks = 1
min_interval = 1
mode = get # mandatory
offset = 50%
srcfile = /public_html/test1MB.dat # mandatory
step = 300
timeout = 60 # mandatory

# The following variables can be overridden in each target section
#localaddr = myhost-nat-if
passive = yes
pings = 5
port = 21


 +DNS

 binary = /usr/bin/dig # mandatory
 forks = 5
 offset = 50%
 step = 480
 timeout = 15

 # The following variables can be overridden in each target section
 lookup = www.whirlpool.net.au
 pings = 5
 server = 203.167.127.1

And my Targets file looks like this:

                       File: /etc/smokeping/config.d/Targets                                                    


 *** Targets ***
 probe = FPing

 menu = Top
 title = Network Latency Grapher
 remark = Welcome to this SmokePing website.

 + local
 menu = Local Hosts
 title = Local Network Devices

 ++ loopback
 host = 127.0.0.1
 title = Localhost (127.0.0.1)
 ++ router
 host = 192.168.88.1
 title = Local CPE Router/Gateway

 + amnet
 menu = Amnet network
 title = Hosts on Amnet network

 ++ amnet-FTP
 menu = Amnet FTP server
 host = 203.161.125.11
 title = Amnet FTP (203.161.125.11)

 ++ amnet-DNS
 host = 203.161.127.1
 title = Amnet DNS (203.161.127.1)
 menu = Amnet DNS

 ++ amnet-first-hop
 host = 203.161.65.253
 title = Amnet First Hop (203.161.65.253)
 menu = First Hop

 ++ amnet-second-hop
 host = 203.161.65.41
 title = Amnet Second Hop (203.161.65.41)
 menu = Second Hop

++ amnet-peer
 host = *******
 title = Amcom Peer (10/10 Corp. Fiber)
 menu = Amcom Peer

 ++ another-peer
 host = 203.161.***.***
 title = Amnet Peer (ADSL2+ Residential)
 menu = Amnet Peer
 remark = Another ADSL2+ customer

 + internet
 menu = Internet
 title = Internet hosts

 ++ google
 host = 8.8.8.8
 title = Google DNS (8.8.8.8)
 menu = Google DNS
 FTP
menu = FTP Throughput
title = FTP throughput

++ Amnet-FTP
remark = Time taken to fetch 1MB file from ftp.amnet.net.au (smaller is better).
probe = FTPtransfer
host = ftp.amnet.net.au
passive = yes
timeout = 120
username = $username
password = $password
port = 21

+ DNS
menu = DNS Servers

++ Amnet-DNS
probe = DNS # if the default probe is something else
host = 203.167.127.1
lookup = www.whirlpool.net.au
pings = 5
server = 203.167.127.1
remark = 5 looksups to 203.167.127.1, every 8 mins
title = Amnet DNS

Leave a Reply

Your email address will not be published. Required fields are marked *