Simon Hearne

Web Performance Consultant

Email Twitter LinkedIn Github RSS

Collecting SpeedTest results in Influx on Raspberry Pi

Published , last modified on

How to set up regular SpeedTest reports into a local InfluxDB on a Raspberry Pi

❤️ 2 likes 🔁 1 repost 💬 2 comments as of 22:00, July 4

Now that you’ve got your Pi set up with Influx & Grafana and you’re collecting some system stats, it’s time to measure network performance! by Ookla is probably the most popular connection testing services, and they handily provide a CLI to run tests programmatically. We’ll create a simple python script which runs a test and sends the data to influxdb, then set it to run once every 15 minutes using Cron.

First, we need to install the speedtest-cli client:

sudo apt install -y python-pip
sudo pip install speedtest-cli influxdb

Then we can create a python script in our home directory to run tests:

#!/usr/bin/env python

import datetime
import speedtest
from influxdb import InfluxDBClient

# influx configuration - edit these
ifuser = "grafana"
ifpass = "<yourpassword>"
ifdb   = "home"
ifhost = ""
ifport = 8086
measurement_name = "speedtest"

# take a timestamp for this measurement
time = datetime.datetime.utcnow()

# run a single-threaded speedtest using default server
s = speedtest.Speedtest()
res = s.results.dict()

# format the data as a single measurement for influx
body = [
        "measurement": measurement_name,
        "time": time,
        "fields": {
            "download": res["download"],
            "upload": res["upload"],
            "ping": res["ping"]

# connect to influx
ifclient = InfluxDBClient(ifhost,ifport,ifuser,ifpass,ifdb)

# write the measurement

View gist on GitHub

We’ll need to make it executable: chmod +x and then we can run it to test it out: ./ You should be able to see the measurement in influx as soon as the script has exited, check by running influx CLI and execute the following to check your measurement (swapping database and measurement names for those you defined in your python script):

use home
select * from speedtest

If everything looks ok, we can add a cron job for our user (using crontab -e) to run this script at a regular interval, e.g. every 15 minutes: */15 * * * * /home/pi/ Any more than 15 minutes is probably unnecessary and may have an adverse effect on your perceived network quality.

You can now simply add a panel to your Grafana instance to show the download, upload and ping results over time. Here is a sample dashboard you can import which includes the panel shown below:

SpeedTest Grafana dashboard.

Join the conversation

The comments on this page are fed by tweets, using, and a modified version of jekyll-webmention_io. To comment, just send a webmention or use a link below to interact via twitter (comments are fetched if the full URL is referenced in the tweet). Webmentions are pulled once per day.

Recent reposts

Recent comments

  1. Paul Armstrong

    Mine is done with @home_assistant, stored to InfluxDB and graphed with Grafana :)

  2. David McKay

    Nice stack 😀