Skip to content

Commit

Permalink
Merge pull request #12 from MiguelNdeCarvalho/feature/server-selection
Browse files Browse the repository at this point in the history
Use custom server if provided
  • Loading branch information
MiguelNdeCarvalho authored Oct 5, 2020
2 parents 3777f77 + 04f9408 commit 028fd2d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import datetime
import time
import os
from prometheus_client import start_http_server, Gauge

def bytes_to_bits(bytes_per_sec):
Expand All @@ -20,6 +21,11 @@ def is_json(myjson):

def run_speedtest():
cmd = ["speedtest", "--format=json-pretty", "--progress=no", "--accept-license", "--accept-gdpr"]
server = os.environ.get('SPEEDTEST_SERVER')
if server:
if server.isnumeric():
print("Using custom server ID: "+str(server))
cmd.append("--server-id="+str(server))
output = subprocess.check_output(cmd)
if is_json(output):
data = json.loads(output)
Expand Down

0 comments on commit 028fd2d

Please sign in to comment.