Performs speedtest-cli tests and pushes metrics to Prometheus Pushgateway
Project description
Prometheus Speedtest
Instrument Speedtest.net tests from Prometheus. Provides metrics on download_speed, upload_speed, and latency.
Getting Started
These instructions will install and run prometheus_speedtest
on your system.
PyPi Package
prometheus_speedtest
is provided as a
PyPi package.
-
Installing
pip3 install prometheus_speedtest
-
Running
prometheus_speedtest
Usage
usage: prometheus_speedtest [-h] [-p port] [-v]
Instrument speedtest.net speedtests from Prometheus.
optional arguments:
-h, --help show this help message and exit
-p port, --port port port to listen on (default: 8080)
-v, --version show version information and exit
Running with Docker
prometheus_speedtest
is also available as a Docker image
on Docker Hub
:whale:.
docker run --rm -d --name prometheus_speedtest -p 8080:8080/tcp jraviles/prometheus_speedtest:latest
Integrating with Prometheus
prometheus_speedtest
is best when paired with
Prometheus. Prometheus can be configured to perform
Speedtests on an interval and record their results.
Speedtest metrics available to query in Prometheus.
Metric Name | Description |
---|---|
download_speed_bps | Download speed (bit/s) |
upload_speed_bps | Upload speed (bit/s) |
ping_ms | Latency (ms) |
bytes_received | Bytes received during test |
bytes_sent | Bytes sent during test |
prometheus.yml config
Add this to your Prometheus config to start instrumenting Speedtests and recording their metrics.
global:
scrape_timeout: 60s
scrape_configs:
- job_name: 'speedtest'
metrics_path: /probe
static_configs:
- targets:
- localhost:8080
Note if you're running prometheus
under Docker, you must link the
prometheus
container to prometheus_speedtest
. See the steps below for how
this can be done.
Trying it out
An example
Prometheus config
has been provided at
example/prometheus.yml.
We'll start prometheus
with this config.
-
Docker Network
Create the Docker network that will link
prometheus_speedtest
andprometheus
together.docker network create prometheus_network
-
Start Prometheus Speedtest
docker run --rm -d --net prometheus_network -p 8080:8080/tcp \ --name prometheus_speedtest jraviles/prometheus_speedtest:latest
-
Start Prometheus
docker run --rm -d --net prometheus_network -p 9090:9090/tcp \ -v $PWD/example/prometheus.yml:/etc/prometheus/prometheus.yml \ --name prometheus prom/prometheus:latest
-
Query results
-
Visit http://localhost:9090
-
Wait around 45 seconds for Prometheus to perform a Speedtest
-
Issue a query for download_speed_bps
You should see something like this.
-
Instrumenting Speedtests with cURL
Once prometheus_speedtest
has been started, with either Docker or PyPi,
Speedtests can be instrumented with cURL.
$ curl localhost:8080/probe
# HELP download_speed_bps Download speed (bit/s)
# TYPE download_speed_bps gauge
download_speed_bps 88016694.95692767
# HELP upload_speed_bps Upload speed (bit/s)
# TYPE upload_speed_bps gauge
upload_speed_bps 3415613.277989314
# HELP ping_ms Latency (ms)
# TYPE ping_ms gauge
ping_ms 20.928
# HELP bytes_received Bytes received during test
# TYPE bytes_received gauge
bytes_received 111342756.0
# HELP bytes_sent Bytes sent during test
# TYPE bytes_sent gauge
bytes_sent 5242880.0
You can also visit http://localhost:8080 in your browser to see the same metrics.
Getting Started (Development)
These instructions will get you a copy prometheus_speedtest
up and running on
your local machine for development and testing purposes.
Prerequisites
Running Locally
Python
-
Ensure packages listed in requirements.txt are installed with
pip3
pip3 install -r requirements.txt
-
Run
prometheus_speedtest
python3 -m prometheus_speedtest.prometheus_speedtest
Docker
-
Building image
docker build -t prometheus_speedtest:latest .
-
Running
docker run --rm -d --name prometheus_speedtest -p 8080:8080/tcp prometheus_speedtest:latest
Perform a Speedtest
curl localhost:8080/probe
Or visit http://localhost:8080
Running Unit Tests
pytest-3
Contributing
Pull requests are welcome. Please adhere to the Google Python style guide.
Please format your contributions with the yapf formatter and lint your code with pylint. A .pylintrc config has been provided.
yapf -i **/*.py
pylint3 **/*.py
Maintenance
Deploying to PyPi
-
Increment version number in version.txt
-
Create PyPi package
python3 setup.py sdist
-
Upload package to PyPi
Ensure that Twine has been installed.
twine upload dist/*
Authors
- Jean-Ralph Aviles
License
This product is licensed under the Apache 2.0 license. See LICENSE file for details.
Acknowledgments
- Matt Martz speedtest-cli
- The Prometheus team https://prometheus.io
- Testing in Python team http://lists.idyll.org/listinfo/testing-in-python
- Benjamin Staffin python-glog
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for prometheus_speedtest-0.4.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98c6f72883b625f606f4ba67b481828f2bb4da05104a27909b50c92f0284305a |
|
MD5 | 45d9f6ce052f37eef49743e4f04a3a9d |
|
BLAKE2b-256 | 009b178bbc0a6a73aa06f12561f873fb2876f1dfb2e59baae775ac03b7a5dac7 |