From 7e02c0ad782fc7cde06eb1712ce50f4a02e02ebc Mon Sep 17 00:00:00 2001 From: Luc VOISE Date: Fri, 16 Oct 2020 15:30:08 +0200 Subject: [PATCH 1/3] Add specific server id --- Dockerfile | 2 +- main.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b508ef..888fa80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/main.py b/main.py index 9c3b4b2..f2ac46c 100755 --- a/main.py +++ b/main.py @@ -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:") From 2e145441851c31d2bd7f800d733c3d26a8c4f6cf Mon Sep 17 00:00:00 2001 From: Sky007FR Date: Fri, 16 Oct 2020 15:57:48 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cc8984f..0656748 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ The variables available are: - INFLUX_DB_TAGS = *comma seperated list of tags. See below for options* - SPEEDTEST_INTERVAL = 60 - SPEEDTEST_FAIL_INTERVAL = 5 +- SPEEDTEST_SERVER_ID = *id from https://c.speedtest.net/speedtest-servers-static.php* ### Variable Notes - Intervals are in minutes. *Script will convert it to seconds.* @@ -58,7 +59,7 @@ Be aware that this script will automatically accept the license and GDPR stateme 1. Build the container. - `docker build -t breadlysm/speedtest-to-influxdb ./` + `docker build -t sky007fr/speedtest-to-influxdb ./` 2. Run the container. ``` @@ -70,13 +71,14 @@ Be aware that this script will automatically accept the license and GDPR stateme -e 'INFLUX_DB_DATABASE'='speedtest' \ -e 'SPEEDTEST_INTERVAL'='1800' \ -e 'SPEEDTEST_FAIL_INTERVAL'='60' \ - breadlysm/speedtest-to-influxdb + -e 'SPEEDTEST_SERVER_ID'='12746' \ + sky007fr/speedtest-to-influxdb ``` ### No Container 1. Clone the repo - `git clone https://github.com/breadlysm/speedtest-to-influxdb.git` + `git clone https://github.com/sky007fr/speedtest-to-influxdb.git` 2. Configure the .env file in the repo or set the environment variables on your device. @@ -94,4 +96,4 @@ Be aware that this script will automatically accept the license and GDPR stateme -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/martinfrancois/speedtest-to-influxdb. They did the hard work, I've continued to modify it though to fit my needs. +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. From 34c71dce652238123462f26be6cb2d69eb3e20d0 Mon Sep 17 00:00:00 2001 From: Luc VOISE Date: Fri, 16 Oct 2020 17:20:09 +0200 Subject: [PATCH 3/3] Add print for log debug --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index f2ac46c..5f3ddbf 100755 --- a/main.py +++ b/main.py @@ -138,17 +138,18 @@ def main(): print("Manual server choice : ID = " + SERVER_ID) if speedtest.returncode == 0: # Speedtest was successful. data = format_for_influx(speedtest.stdout) - print("Speedtest Successful:") + print("Speedtest Successful :") + print(speedtest.stdout) if influxdb_client.write_points(data) == True: print("Data written to DB successfully") time.sleep(TEST_INTERVAL) else: # Speedtest failed. - print("Speedtest Failed:") + print("Speedtest Failed :") print(speedtest.stderr) print(speedtest.stdout) time.sleep(TEST_FAIL_INTERVAL) if __name__ == '__main__': - print('Speedtest CLI Data Logger to InfluxDB') + print('Speedtest CLI data logger to InfluxDB started...') main()