The case of monitoring your internet speed during a pandemic
Tags: speedtest, docker, isp, corona
Published: 2021-01-24 16:42:48

**TL;DR:** Not interested in the background and just want to know how to monitor your internet speed regularly? [Jump right to it](#monitoring-internet-speed)

I live in Germany, and I know that we don't have the fastest internet in the world. Still, with a mean download speed of 42.33 Mbps, the country does better than the global average of 24.83 Mbps. Nevertheless, it is just enough to place 42<sup>nd</sup> out of 221 countries compared.[^1] In comparison with only the European countries, Germany does not even make it into the top 10, placing 26<sup>th</sup>.[^1]

With digitization as one of the thriving factors for the world economy, the internet and connectivity to it start playing an ever more important role, as it is the foundation that digitization needs to flourish.[^digitization]

Currently, Germany is the 13<sup>th</sup> biggest economy in the world - placing 8<sup>th</sup> within Europe - measured by the gross domestic product (GDP) per capita, adjusted with purchasing power parity.[^gdp] So, one could expect to have a fast, reliable internet connection. At least, the comparably high economic strength of Germany ($ 56K) does not seem to have a significant effect on the price of an internet contract. However, it is noteworthy that Luxembourg, as the country with the strongest economic power within Europe ($ 121K) gets better value (internet speed of avg. 118 Mbps) for a lower price.[^price] Given that Luxembourg is a lot smaller than Germany, the countries face different challenges when it comes to getting the internet to where the people live. Therefore, it is an interesting fact, but one to be neglected.

Lately, the pandemic urges people to work from home wherever possible, and with schools and universities closed, the internet infrastructure in Germany is put to a test. During the day employees, students, pupils working from home put an unprecedented load on the infrastructure. From the afternoon to the evening and night, when people stop working and switch their internet usage to scrolling through Instagram, TikTok, etc., and streaming their favorite shows on Netflix, Prime, and so on.

The additional stress this puts on the internet service providers (ISPs) can be felt by customers. In my case, living in a densely populated area (a.k.a city), the result was that I had no internet connection at home between 8 a.m. and 11 p.m., making it impossible for me to work from home, or stream anything. I have a contract promising up to 50 Mbps and no less than 25 Mbps. For the past years, this was sufficient and I never had any serious problems with it. Now,  in the middle of the second "lockdown", I effectively have no internet during the day.

Getting curious to see how much my internet speed varies throughout the day (and night) gave me the idea for this post.

-------------

## Monitoring internet speed <a name="monitoring-internet-speed"></a>

![Speed Test Dashboard](https://raw.githubusercontent.com/sthuber90/docker-speedtest/main/docs/img/dashboard.png)

While there are numerous tools out there to test your internet speed[^speedtests], [Ookla's speedtest CLI](https://www.speedtest.net/apps/cli) seemed like the perfect fit. You can simply download it, it's well documented, it requires no additional tools, it comes from the official source, and seems to be maintained in contrast to others[^others]. Running the speed test from my PC was a no go. First of all, the test would run on my WiFi, possibly distorting the results. Secondly, it would not monitor the connection day and night, but only run when my PC is on, so only when I work. Furthermore, it would likely distort the results more, as I depend on the internet, namely Stackoverflow, to work. Luckily, I have a RaspberryPi connected to my router. Services already deployed on the RaspberryPi, run only as Docker containers. Therefore, I aimed to run the speed test from a Docker container too and to keep the OS free from all that is unnecessary.

The final result can be found on GitHub:

{% github sthuber90/docker-speedtest no-readme %}

The repository contains the code, that is used to build the [sthuber90/docker-speedtest](https://hub.docker.com/r/sthuber90/speedtest/) Docker image. The container can be configured to run a speed test every 5 minutes (default: 15 minutes). Be aware, that if you run this image, you agree to the Speedtest CLI's license and privacy regulations.

The results of the speed test are intended to be forwarded to an InfluxDB and visualized in a Chronograf dashboard (provided in the repository). Detailed instructions to set up the monitoring can be found in the README on GitHub and Docker Hub. 

I hope you did find this post helpful.


<!--  ----------------   References  ----------------    -->

[^1]: https://www.cable.co.uk/broadband/speed/worldwide-speed-league/, 2020

[^price]: https://www.cable.co.uk/broadband/pricing/worldwide-comparison/, 2020

[^speedtests]: https://fast.com (by Netflix), http://avm.de/nc/service/zack-der-speedtest-fuer-ihre-breitbandverbindung/, https://breitbandmessung.de/ (by the German Federal Network Agency)

[^gdp]: GDP from 2019, considering PPP (World Bank: https://data.worldbank.org/indicator/NY.GDP.MKTP.PP.CD?end=2019&most_recent_value_desc=true&start=1990&view=chart) turned into GDP per capita in USD, taking the countries population into account (World Bank:  https://data.worldbank.org/indicator/SP.POP.TOTL?most_recent_value_desc=true), 2019

[^digitization]: PwC, https://www.strategyand.pwc.com/m1/en/reports/digitization-for-economic-growth-and-job-creation.pdf, 2013

[^others]: Other libraries using https://speedtest.net for internet speed tests, that seem not to be maintained anymore  (1) https://www.npmjs.com/package/speedtest, (2) https://pypi.org/project/speedtest-cli/