Add specific server id

This commit is contained in:
Luc VOISE 2020-10-16 15:30:08 +02:00
parent ceba7dc5b2
commit 7e02c0ad78
2 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,6 @@
FROM python:3.8-slim-buster
LABEL maintainer="Josh Smith" \
LABEL maintainer="Luc VOISE" \
description="Original by Aiden Gilmartin. Speedtest to InfluxDB data bridge"
# Install dependencies

12
main.py
View File

@ -17,6 +17,8 @@ DB_TAGS = os.environ.get('INFLUX_DB_TAGS')
TEST_INTERVAL = int(os.environ.get('SPEEDTEST_INTERVAL')) * 60
# Time before retrying a failed Speedtest (in minutes, converts to seconds).
TEST_FAIL_INTERVAL = int(os.environ.get('SPEEDTEST_FAIL_INTERVAL')) * 60
# Specific server ID
SERVER_ID = os.environ.get('SPEEDTEST_SERVER_ID')
influxdb_client = InfluxDBClient(
DB_ADDRESS, DB_PORT, DB_USER, DB_PASSWORD, None)
@ -125,9 +127,15 @@ def main():
init_db() # Setup the database if it does not already exist.
while (1): # Run a Speedtest and send the results to influxDB indefinitely.
speedtest = subprocess.run(
server_id = SERVER_ID
if not server_id:
speedtest = subprocess.run(
["speedtest", "--accept-license", "--accept-gdpr", "-f", "json"], capture_output=True)
print("Automatic server choice")
else :
speedtest = subprocess.run(
["speedtest", "--accept-license", "--accept-gdpr", "-f", "json", "--server-id=" + SERVER_ID], capture_output=True)
print("Manual server choice : ID = " + SERVER_ID)
if speedtest.returncode == 0: # Speedtest was successful.
data = format_for_influx(speedtest.stdout)
print("Speedtest Successful:")