Monitor your internet speed using k8s and prometheus.
Sunday, May 29th 2022

In this post we will implement an Internet connection monitor using prometheus. We will use speedtest.net to periodically run speed tests and feed results into prometheus. This post only outlines the functionality and assumes a certain amount of knowledge with docker, k8s, prometheus and grafana.

This is the high level game plan. We will:

  • Create our own docker image containing the speedtest.net binary.
  • Create the script that will parse output from speedtest.net binary.
  • Push metrics to Prometheus Pushgateway.
  • Push image to private registry.
  • Create k8s cronjob to periodically run the job.

In order to achieve all that we assume a working installation of Prometheus (with pushgateway installed and configured as a target), a private image registry and a grafana installation.

Prometheus pushgateway is used as a workaround method of ingesting metrics. Scripts can push metrics to prometheus pushgateway. The gateway then exposes a prometheus-compatible page that displays all data received. Prometheus then scrapes this page and ingests all metrics.

Be sure to read up the documentation about the pushgateway and when to use it.

All code can be found in this Github repository.


The docker image can be run with the following command and expects 2 environment variables:

$ docker run -ti --rm --name speedtest speedtest:1 -e SERVERID=<SERVER_ID> -e PROJECTNAME=<PROJECT_NAME>

Be sure to substitute <SERVER_ID> with a server of your choice and <PROJECT_NAME> with something relevant.


Now that you have tuned all settings you can create the final docker image and push it to your private registry.

Once you have done that you can use the sample yaml file to deploy a cronjob that will invoke this process periodically. Just make sure to update all relevant values in speedtest.yaml to your liking before applying.

Once the cronjob runs it will push all metrics to Prometheus pushgateway. Now you can create your grafana dashboard. A sample one has been provided here. Once more, adjust all settings to your liking and have fun!

This is the end result:

Grafana dashboard