Musings of a Fondue

Speed Test - Raspberry PI

We were having some problems with consistent internet speed. I wanted to see how it varied over time by gathering a week’s worth of data and visualizing it with D3.

One option was to manually run the speed tests periodically. A more sane option, was to have a program do this.

I didn’t want to leave my computer forever on to accomplish this. And there was a Raspberry Pi sitting unused, that could stay running for days on end happily. So Pi it was.

But how to write such a program?

Via a Google search, I came across this great article on checking internet speed from the command line. The article gives a great rundown on how to install and use Matt Martz’s speedtest-cli (a command-line interface of the popular speedtest.net).

I knew I wanted it to run every half hour, and output the download speed to a text file.

For the every half hour bit, it turned out not so bad. I came across the linux command cron and this article on how to use it. And calling the script every half hour became a one liner,


/30 * * * * speedtest-cli

For the output to a text file, a google search turned up tee another linux command and this article on how to use it. Outputing to a text file also became a one liner,


speedtest-cli | tee -a /home/pi/Desktop/speed_log.txt

But, speedtest-cli doesn’t show time! Since it’s a python file, I opened it up and added it (Yes that’s a very crude way to go about it, but meh).


print_('Time: ' + str(datetime.now()))  

While I was there, I tweaked some of the other outputs to make scrubbing the data later easier. For example, this


print_('Testing from %(isp)s (%(ip)s)...' % config['client'])   

became this,


print_('Testing_from : %(isp)s (%(ip)s)...' % config['client']) 

And that’s it lol!

Here is a sample of the data I collected,


Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : Cybera (Calgary, AB) [15.68 km]
Ping : 247.637 ms
Download : 26.16 Mbit/s
Upload : 2.41 Mbit/s
Time : 2014-04-24 13:29:00.410586
endBlock
Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : TELUS (Calgary, AB) [15.68 km]
Ping : 243.743 ms
Download : 25.91 Mbit/s
Upload : 2.40 Mbit/s
Time : 2014-04-24 13:59:39.016899
endBlock
Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : O-NET (Olds Fibre Ltd.) (Olds, AB) [70.55 km]
Ping : 247.717 ms
Download : 21.28 Mbit/s
Upload : 2.44 Mbit/s
Time : 2014-04-24 14:30:22.451536
endBlock
Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : TELUS (Calgary, AB) [15.68 km]
Ping : 247.32 ms
Download : 26.06 Mbit/s
Upload : 2.38 Mbit/s
Time : 2014-04-24 15:01:02.943264
endBlock
Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : NETAGO (Hanna, Alberta) [165.47 km]
Ping : 248.114 ms
Download : 24.45 Mbit/s
Upload : 2.47 Mbit/s
Time : 2014-04-24 15:31:44.987950
endBlock
Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : TELUS (Calgary, AB) [15.68 km]
Ping : 243.823 ms
Download : 25.10 Mbit/s
Upload : 2.41 Mbit/s
Time : 2014-04-24 16:02:28.680747
endBlock
Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : NETAGO (Hanna, Alberta) [165.47 km]
Ping : 242.313 ms
Download : 21.18 Mbit/s
Upload : 2.40 Mbit/s
Time : 2014-04-24 16:33:04.073389
endBlock
Testing_from : Shaw Communications (xxx.xx.xx.xx)...
Hosted_by : TELUS (Calgary, AB) [15.68 km]
Ping : 251.373 ms
Download : 17.86 Mbit/s
Upload : 2.44 Mbit/s
Time : 2014-04-24 17:03:41.853103
endBlock

Comments