speedtest-to-influxdb2/README.md

102 lines
5.6 KiB
Markdown
Raw Normal View History

# Speedtest to InfluxDBv2
2021-04-27 17:39:03 +00:00
---
This is a Python script that will continuously run the official Speedtest CLI application by Ookla, takes input from environment variables, formats data and writes it to an InfluxDB v2 database.
This script will allow you to measure your internet connections speed and consistency over time. It uses env variables as configuration. It's as easy to use as telling your Docker server a 1 line command and you'll be set. Using Grafana you can start exploring this data easily.
2020-09-23 02:18:22 +00:00
Breadlysm built a grafana dashboard for this data that can be found at https://grafana.com/grafana/dashboards/13053. Additionally, other contributors have modified this dash and included a JSON file of those modifications. Use `GrafanaDash-SpeedTests.json` to import that dash into Grafana.
2021-04-27 17:39:03 +00:00
![OriginalDash](https://user-images.githubusercontent.com/3665468/116284820-8038ca00-a75b-11eb-9b30-4a9d26434f8d.png)
![Variant](https://user-images.githubusercontent.com/945191/105287048-46f52a80-5b6c-11eb-9e57-038d63b67efb.png)
There are some added features to allow some additional details that Ookla provides as tags on your data. Some examples are your current ISP, the interface being used, the server who hosted the test. Overtime, you could identify if some serers are performing better than others.
## Differences to InfluxDB v1 program:
* Slightly different environment variables to set up InfluxDB connection
* Speeds will be returned in bytes without transforming into MBit/s, just like the speedtest does
* The measure duplication of `speeds>bandwith_up/down` and `download>bandwith` and `upload>bandwith` has been removed, leaving only the `speeds` fields. Same thing with `ping` and `speeds>latency/jitter` duplication.
* Setting a ping/speedtest interval of 0 will turn the respective test off
* By default only failed tests will be printed to stdout/stderr, this can be controlled through `SPEEDTEST_DEBUG`
2020-07-31 05:10:51 +00:00
## Configuring the script
The InfluxDB connection settings are controlled by environment variables.
The variables available are:
2021-01-17 01:17:35 +00:00
- NAMESPACE = default - None
- INFLUX_DB_ADDRESS = default - influxdb:8086
- INFLUX_DB_TOKEN = no default, *required* for any operation
- INFLUX_DB_ORG = default - speed-org
- INFLUX_DB_BUCKET = default - speedtests
- INFLUX_DB_VERIFY_SSL = default - True
- INFLUX_DB_TAGS = default - None * See below for options, `'*'` widcard for all *
2021-01-20 07:06:51 +00:00
- SPEEDTEST_INTERVAL = default - 5 (minutes)
2021-01-17 01:17:35 +00:00
- SPEEDTEST_SERVER_ID = default - {blank} * id from https://c.speedtest.net/speedtest-servers-static.php *
2021-01-20 07:06:51 +00:00
- PING_INTERVAL = default - 5 (seconds)
2021-01-21 06:12:32 +00:00
- PING_TARGETS = default - 1.1.1.1, 8.8.8.8 (csv of hosts to ping)
- SPEEDTEST_DEBUG = default - False
2020-07-31 05:10:51 +00:00
### Variable Notes
- Intervals are in minutes. *Script will convert it to seconds.*
- If any variables are not needed, don't declare them. Functions will operate with or without most variables.
2020-07-31 05:10:51 +00:00
- Tags should be input without quotes. *INFLUX_DB_TAGS = isp, interface, external_ip, server_name, speedtest_url*
- NAMESPACE is used to collect data from multiple instances of the container into one database and select which you wish to view in Grafana. i.e. Breadlysm has one monitoring their Starlink, the other their TELUS connection.
2020-07-31 05:10:51 +00:00
### Tag Options
The Ookla speedtest app provides a nice set of data beyond the upload and download speed. The list is below.
2020-07-31 05:10:51 +00:00
| Tag Name | Description |
|- |- |
| isp | Your connections ISP |
| interface | Your devices connection interface |
| internal_ip | Your container or devices IP address |
| interface_mac | Mac address of your devices interface |
| vpn_enabled | Determines if VPN is enabled or not? I wasn't sure what this represented |
| external_ip | Your devices external IP address |
| server_id | The Speedtest ID of the server that was used for testing |
| server_name | Name of the Speedtest server used for testing |
| server_country | Country where the Speedtest server resides |
2020-12-20 23:44:41 +00:00
| server_location | Location where the Speedtest server resides |
2020-07-31 05:10:51 +00:00
| server_host | Hostname of the Speedtest server |
| server_port | Port used by the Speedtest server |
| server_ip | Speedtest server's IP address |
| speedtest_id | ID of the speedtest results. Can be used on their site to see results |
| speedtest_url | Link to the testing results. It provides your results as it would if you tested on their site. |
### Additional Notes
Be aware that this script will automatically accept the license and GDPR statement so that it can run non-interactively. Make sure you agree with them before running.
2020-07-31 05:10:51 +00:00
## Running the Script
### Ideal option, run as a Docker container.
2020-07-31 05:10:51 +00:00
1. Build the container.
`docker build -t speedtest-to-influxdbv2 ./`
2020-07-31 05:10:51 +00:00
2. Run the container.
```
2021-04-27 17:39:03 +00:00
docker run -d -t --name speedflux \
2021-01-17 01:17:35 +00:00
-e 'NAMESPACE'='None' \
-e 'INFLUX_DB_ADDRESS'='influxdb:8086' \
-e 'INFLUX_DB_ORG'='my-awesome-org' \
-e 'INFLUX_DB_TOKEN'='1NCR3D1BLY-L0NG-T0K3N-ST71NG' \
-e 'INFLUX_DB_BUCKET'='speedtests' \
2021-01-17 01:17:35 +00:00
-e 'SPEEDTEST_INTERVAL'='5' \
-e 'SPEEDTEST_FAIL_INTERVAL'='5' \
2020-10-16 13:57:48 +00:00
-e 'SPEEDTEST_SERVER_ID'='12746' \
speedtest-to-influxdbv2
2020-07-31 05:10:51 +00:00
```
As of now, the container is also reachable through this repository's container registry:
2021-04-27 17:39:03 +00:00
`docker run <FLAGS> registry.gitlab.com/marty-oehme/speedtest-to-influxdb2:master`
2021-04-27 17:39:03 +00:00
---
2020-10-16 13:57:48 +00:00
This script looks to have been originally written by https://github.com/aidengilmartin/speedtest-to-influxdb/blob/master/main.py and I forked it from https://github.com/breadlysm/speedtest-to-influxdb. They did the hard work, I've continued to modify it though to fit my needs.