Simple Command Line Download Speed Test

I got a server that started to have a bad network connection. To help debugging this I needed to collect some data, e.g. of running a download test every 5 minutes.

A quick search revealed nothing so I found a simple way to do that with curl and Google Drive.

1. Google Drive Form

I set up a simple Google Drive form that accepts two text values:
Next I need to find out the HTML form field names of these two fields. This takes a little bit of digging.   There is always a label attached to each input field. They are connected via the for attribute of the label.
With this information I can now construct a simple curl script.

2. CURL script to collect some data and post

I want curl to try to download a URL and record the download speed. The -w, -y and -Y options come in handy for this purpose:
  • -w lets me output only the information I really care about (the speed of the download in Bytes per second)
  • -y gives a timeout after which curl will abort the download
  • -Y gives a minimum download speed (in B/s). If after -y seconds this is not achieved then the download is aborted. Choosing a very high number ensures that the download will never run longer than 60 seconds.
curl -w "%{speed_download}" -y 60 -Y 100000000000000 -s -o /dev/null "$1"
runs at most 60 seconds and prints the average download speed (e.g. 546746.000) to standard out.

The result is posted to Google Drive with another curl call. I use -s -o /dev/null as I don't care about the output of the download or the data post. The complete script looks like this:
This is it! The relevant part is curl -d <form field id>=<form field data> and the right URL of the form. Filling the form fields with a subshell $(...) is just a short form that does not need extra variables.

Call the script from a cron job and watch how data starts collecting in your Google Drive. I can even run it on different systems (giving me different probes to provide data) and later aggregate or filter the data.

I don't need to send a timestamp as this is added automatically by Google Drive Forms.

3. Google Drive spreadsheet for data analysis

In the Google Drive form one must select a destination spreadsheet for the results. In that spreadsheet I created a Chart, mark the two columns timestamp and speed and set the chart type to Trend and Timeline. The result looks already very useful:
The chart has its own publish button which gives a JavaScript block. In this block I only had to adjust the width: and height: settings to format the chart and replace the range with A:B so that it would take all the data.

Note: The spreadsheet should be set to a US or UK locale so that the XXX.000 numbers created by curl will be parsed correctly. For other locales you might have to strip the .000 before posting the data.

4. Doing this for multiple targets

The whole point of this exercise was to monitor the service quality of a VPS hoster. As the service quality is still below my needs I got another VPS at another hoster so that I had to setup the same monitoring for the other hoster as well. 

It turns out that this is really simple. I can just copy the form in Google Drive and get a new form that uses the same keys for the input fields! That makes it really easy to customize my little script like this:
And the results of the other hoster look like this:

As we can see here, the other hoster is doing much better :-)


Like this content? You could send me something from my Amazon Wishlist. Need commercial support? Contact me for Consulting Services.

Popular posts from this blog

Overriding / Patching Linux System Serial Number

A Login Security Architecture Without Passwords

The Demise of KaiOS - Alcatel 3088X