Package: prometheus-speedtest
Prometheus SpeedtestInstrumentSpeedtest.nettests fromPrometheus. Provides metrics on download_speed,
upload_speed, and latency.Getting StartedThese instructions will install and runprometheus_speedteston your system.PyPi Packageprometheus_speedtestis provided as aPyPi package.Installingpipinstallprometheus_speedtestRunningprometheus_speedtestUsageInstrument speedtest.net speedtests from Prometheus.
flags:

prometheus_speedtest.py:
  --address: address to listen on
    (default: '0.0.0.0')
  --excludes: speedtest server(s) to exclude - leave empty for no exclusion
    (a comma separated list)
  --port: port to listen on
    (default: '9516')
    (an integer)
  --servers: speedtest server(s) to use - leave empty for auto-selection
    (a comma separated list)
  --[no]version: show version
    (default: 'false')Running with Dockerprometheus_speedtestis also available as aDockerimage
onDocker Hub:whale:.dockerrun--rm-d--nameprometheus_speedtest-p9516:9516/tcpjraviles/prometheus_speedtest:latestYou can also append extra flags when running with Docker. For example:$dockerrun--rm--nameprometheus_speedtest-p9516:9516/tcp\jraviles/prometheus_speedtest:latest--version
prometheus_speedtestv0.9.9Running with KubernetesSince you can run this from a Docker container, you can also run it in Kubernetes.kubectlapply-fdeploy/namespace.yaml
kubectlapply-fdeploy/deployment.yamlThe Kubernetes YAML files are pre-configured to work with thekubernetes-pods-slowjob that comes with Prometheus, which is configured with
5m scrape times and 30s timeouts.  If you need to raise the timeout, you'll
need to change that in your Prometheus config map.Just keep in mind, that if you increase the replica count, then Prometheus will
run a speedtest for each pod, every 5m. The same goes for if you are running
more than one replica of Prometheus, as each replica independently scrapes
targets.Integrating with Prometheusprometheus_speedtestis best when paired withPrometheus. Prometheus can be configured to perform
Speedtests on an interval and record their results.Speedtest metrics available to query in Prometheus.Metric NameDescriptiondownload_speed_bpsDownload speed (bit/s)upload_speed_bpsUpload speed (bit/s)ping_msLatency (ms)bytes_receivedBytes received during testbytes_sentBytes sent during testprometheus.yml configAdd this to yourPrometheus configto start instrumenting Speedtests and recording their metrics.global:scrape_timeout:2mscrape_configs:-job_name:'speedtest'metrics_path:/probestatic_configs:-targets:-localhost:9516Note if you're runningprometheusunder Docker, you must link theprometheuscontainer toprometheus_speedtest. See the steps below for how
this can be done.Trying it outAn examplePrometheus confighas been provided atexample/prometheus.yml.
We'll startprometheuswith this config.Docker NetworkCreate theDocker networkthat will linkprometheus_speedtestandprometheustogether.dockernetworkcreateprometheus_networkStart Prometheus Speedtestdockerrun--rm-d--netprometheus_network-p9516:9516/tcp\--nameprometheus_speedtestjraviles/prometheus_speedtest:latestStart Prometheusdockerrun--rm-d--netprometheus_network-p9516:9516/tcp\-v$PWD/example/prometheus.yml:/etc/prometheus/prometheus.yml\--nameprometheusprom/prometheus:latestQuery resultsVisithttp://localhost:9516/probeWait around45 secondsfor Prometheus to perform a SpeedtestIssue a query fordownload_speed_bpsYou should see something like this.Instrumenting Speedtests with cURLOnceprometheus_speedtesthas been started, with either Docker or PyPi,
Speedtests can be instrumented withcURL.$curllocalhost:9516/probe# HELP download_speed_bps Download speed (bit/s)# TYPE download_speed_bps gaugedownload_speed_bps88016694.95692767# HELP upload_speed_bps Upload speed (bit/s)# TYPE upload_speed_bps gaugeupload_speed_bps3415613.277989314# HELP ping_ms Latency (ms)# TYPE ping_ms gaugeping_ms20.928# HELP bytes_received Bytes received during test# TYPE bytes_received gaugebytes_received111342756.0# HELP bytes_sent Bytes sent during test# TYPE bytes_sent gaugebytes_sent5242880.0You can also visithttp://localhost:9516/probein your browser to see the same
metrics.Default PortPrometheus Speedtest defaults to running on port 9516; this is the allocated
port for this exporter in thePrometheus Default Port Allocations Guide.Getting Started (Development)These instructions will get you a copyprometheus_speedtestup and running on
your local machine for development and testing purposes.PrerequisitesPythonDockerPytestRunning LocallyPythonEnsure packages listed inrequirements.txtare installed withpippip3install-rrequirements.txtRunprometheus_speedtestpython3-mprometheus_speedtest.prometheus_speedtestDockerBuilding imagedockerbuild-tprometheus_speedtest:latest.Runningdockerrun--rm-d--nameprometheus_speedtest-p9516:9516/tcpprometheus_speedtest:latestPerform a Speedtestcurllocalhost:9516/probeOr visithttp://localhost:9516/probeRunning Unit TestspytestContributingPull requests are welcome. Please adhere to theGoogle Python style guide.Please format your contributions with theyapfformatter and lint your code withpylint. A.pylintrcconfig has been provided.yapf-i**/*.py
pylint**/*.py
pytypeGrafana Dashboard TemplateUser Doğukan Çağatay has created a Grafana dashboard template for
prometheus_speedtest. Go check it out ongrafana.com.MaintenanceDeploying to PyPiIncrement version number inversion.pyCreate PyPi packagepython3setup.pysdistUpload package to PyPiEnsure thatTwinehas been installed.twineuploaddist/*Deploying multi-architecture images to Docker HubEnsure that Docker >= 19.03 anddocker buildxis
installed.Build and push the new image.# Ensure you have run 'docker login'exportDOCKER_CLI_EXPERIMENTAL=enabled# https://github.com/docker/buildx/issues/495#issuecomment-754688157dockerrun--rm--privilegedmultiarch/qemu-user-static--reset-pyes
dockerbuildxcreate--use--namemy-builderTAG="$(python3-mprometheus_speedtest.prometheus_speedtest--version\|cut-d'v'-f2)"dockerbuildxbuild--push--platformlinux/amd64,linux/arm64,linux/arm/v7\-tjraviles/prometheus_speedtest:latest\-tjraviles/prometheus_speedtest:${TAG:?}.
dockerbuildxrmmy-builderAuthorsJean-Ralph AvilesLicenseThis product is licensed under the Apache 2.0 license. SeeLICENSEfile for details.AcknowledgmentsMatt Martzspeedtest-cliThe Prometheus teamhttps://prometheus.ioTesting in Python teamhttp://lists.idyll.org/listinfo/testing-in-pythonBenjamin Staffinpython-glog