From 1797e6aafde55d0d65f5353434d32ac03e51a8c1 Mon Sep 17 00:00:00 2001 From: imp4ct Date: Mon, 27 Jul 2020 21:03:50 -0400 Subject: [PATCH] Created initial code base with some items still not working correctly such as final push to influx server. --- main.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..f9c5de9 --- /dev/null +++ b/main.py @@ -0,0 +1,41 @@ +# Sean Corrigan 2020 +import speedtest +import json +from influxdb import InfluxDBClient + +def speed(): # To be called on schedule + servers = [] # If you want to test against a specific server + threads = 4 + # Choose the amount of threads to use for the test + test = speedtest.Speedtest() + test.get_servers(servers) + test.get_best_server() + test.download(threads=threads) + test.upload(threads=threads) + test.results.share() + + results = test.results.dict() + + + resultlist = [] + resultupload = {} + resultupload["UploadSpeed"] = results["upload"] + resultdownload = {} + resultdownload["DownloadSpeed"] = results["download"] + resultlatency = {} + resultlatency["Latency"] = results["ping"] + resultlist.append(resultupload) + resultlist.append(resultdownload) + resultlist.append(resultlatency) + + resultforupload = json.dumps(resultlist) + print(resultforupload) + + return(resultforupload) + +def influxupload(): # Still having errors in uploading the data.. + jsondata = speed() + client = InfluxDBClient(host='192.168.0.13', port=8086, database='telegraf') + client.write(str(jsondata), protocol='json') + +influxupload() \ No newline at end of file