Telegraf now has an official Internet Speed Monitor plugin. I recommend using that instead.
https://github.com/influxdata/telegraf/tree/master/plugins/inputs/internet_speed
Runs Ookla's Speedtest CLI program in Docker, sends the results to InfluxDB
- Source code: GitHub
- Image base: Python (slim Buster)
- Init system: N/A
- Application: Speedtest CLI
- Architecture:
linux/amd64
- This runs Ooka's Speedtest CLI program on an interval, then writes the data to an InfluxDB database (you can later graph this data with Grafana or Chronograf)
- This does NOT use the open-source speedtest-cli. That program uses the Speedtest.net HTTP API. This program uses Ookla's official CLI application.
⚠️ Ookla's speedtest application is closed-source (the binary applications are here) and Ookla's reasoning for this decision is here⚠️ ⚠️ Ookla's speedtest application reports all data back to Ookla⚠️ ⚠️ This application uses Ookla's recommendation to install by piping curl to bash⚠️ - The default output unit of measurement is bytes-per-second. You will most likely want to convert to megabits-per-second by dividing your output by 125000.
For example, if your download speed is 11702913 bytes-per-second:
11702913 / 125000 = 93.623304 megabits-per-second
- This only works with InfluxDB v1.8 and v2, because I'm using this client library.
- You must already have an InfluxDB database created, along with a user that has
WRITE
andREAD
permissions on that database. - This Docker container needs to be able to reach that InfluxDB instance by hostname, IP address, or Docker service name (I run this container on the same Docker network as my InfluxDB instance).
⚠️ Depending on how often you run this, you may need to monitor your internet connection's usage. If you have a data cap, you could exceed it. The standard speedtest uses about 750MB of data per run. See below for an example.⚠️
CONTAINER: NET I/O
speedtest: 225MB / 495MB
Variable | Required? | Definition | Example | Comments |
---|---|---|---|---|
INFLUXDB_SCHEME | No (default: http) | Connect to InfluxDB using http or https | 'https' | Useful if InfluxDB is behind a reverse proxy and you need to use https |
INFLUXDB_HOST | No (default: localhost) | Server hosting the InfluxDB | 'localhost' or your Docker service name | |
INFLUXDB_PORT | No (default: 8086) | InfluxDB port | 8086 | |
INFLUXDB_USER | Yes (only for v1) | Database username | test1 | Needs to have the correct permissions |
INFLUXDB_PASS | Yes (only for v1) | Database password | test1234 | |
INFLUXDB_TOKEN | Yes (only for v2) | Token to connect to bucket | asdfghjkl | Needs to have the correct permissions. Setting this assumes we're talking to an InfluxDBv2 instance |
INFLUXDB_ORG | Yes (only for v2) | Organization | my_test_org | |
INFLUXDB_DB | Yes | Database name | SpeedtestStats | Must already be created. In InfluxDBv2, this is the "bucket". |
SLEEPY_TIME | No (default: 3600) | Seconds to sleep between runs | 3600 | The loop takes about 15-30 seconds to run, so I wouldn't set this value any lower than 60 (1min) |
SPEEDTEST_HOST | No (default: container ID) | Hostname of service where Speedtest is running | server04 | Useful if you're running Speedtest on multiple servers |
SPEEDTEST_SERVER | No (default: random) | ID number of Speedtest server | 41817 | See a list of servers and IDs here |
N/A
N/A
Below is an example of running locally (used to edit/test/debug).
# Build the Dockerfile
docker compose -f docker-compose-dev.yml up -d
# View logs
docker compose -f docker-compose-dev.yml logs -f
# Destroy when done
docker compose -f docker-compose-dev.yml down
- Learn Python
-
Run the processes inside the container as a non-root user - Add a healthcheck
-
Move the database connection check to a function -
Add logic to check if variables are set -
Add defaults for HOST and PORT - Update CI/CD with tests
-
Add warning about bandwidth - Implement an authentication check when this PR is merged