Add print for log debug
This commit is contained in:
commit
870c7ddcf9
2 changed files with 15 additions and 11 deletions
10
README.md
10
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.
|
||||
|
|
16
main.py
16
main.py
|
@ -74,8 +74,8 @@ def tag_selection(data):
|
|||
return options
|
||||
|
||||
|
||||
def format_for_influx(cliout):
|
||||
data = json.loads(cliout)
|
||||
def format_for_influx(data):
|
||||
|
||||
# There is additional data in the speedtest-cli output but it is likely not necessary to store.
|
||||
influx_data = [
|
||||
{
|
||||
|
@ -132,14 +132,16 @@ def main():
|
|||
speedtest = subprocess.run(
|
||||
["speedtest", "--accept-license", "--accept-gdpr", "-f", "json"], capture_output=True)
|
||||
print("Automatic server choice")
|
||||
else :
|
||||
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)
|
||||
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.stdout)
|
||||
data_json = json.loads(speedtest.stdout)
|
||||
print("time: " + str(data_json['timestamp']) + " - ping: " + str(data_json['ping']['latency']) + " ms - download: " + str(data_json['download']['bandwidth']/125000) + " Mb/s - upload: " + str(data_json['upload']['bandwidth'] / 125000) + " Mb/s - isp: " + data_json['isp'] + " - ext. IP: " + data_json['interface']['externalIp'] + " - server id: " + str(data_json['server']['id']) + " (" + data_json['server']['name'] + " @ " + data_json['server']['location'] + ")")
|
||||
data = format_for_influx(data_json)
|
||||
if influxdb_client.write_points(data) == True:
|
||||
print("Data written to DB successfully")
|
||||
time.sleep(TEST_INTERVAL)
|
||||
|
@ -152,4 +154,4 @@ def main():
|
|||
|
||||
if __name__ == '__main__':
|
||||
print('Speedtest CLI data logger to InfluxDB started...')
|
||||
main()
|
||||
main()
|
Loading…
Reference in a new issue