35
logspeedtest.py
Normal file
35
logspeedtest.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import subprocess as sp
|
||||
import requests
|
||||
import time
|
||||
import json
|
||||
def addinfluxrecord(downspeed,upspeed,pktloss,jitter,latencyavg,minlatency,maxlatency):
|
||||
data = f"Down value={downspeed}\nUp value={upspeed}\nPacketLoss value={pktloss}\nJitter value={jitter}\nLatencyAvg value={latencyavg}\nLatencyLow value={minlatency}\nLatencyHigh value={maxlatency}"
|
||||
print(data)
|
||||
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
response = requests.post(
|
||||
influxuri,
|
||||
data=data,
|
||||
headers=headers,
|
||||
auth=(infdbuser,infdbpass)
|
||||
)
|
||||
return response
|
||||
|
||||
infdbuser = os.environ["INFLUX_USER"]
|
||||
infdbpass = os.environ["INFLUX_PASSWORD"]
|
||||
influxuri = os.environ["INFLUX_URI"]
|
||||
while(True):
|
||||
response = sp.getstatusoutput(f"speedtest --format=json")[1]
|
||||
respjson = json.loads(response.split("\n")[1])
|
||||
print(response)
|
||||
downspeed = respjson['download']['bandwidth'] * 8 / 1024 / 1024
|
||||
upspeed = respjson['upload']['bandwidth'] * 8 / 1024 / 1024
|
||||
pktloss = respjson['packetLoss']
|
||||
jitter = respjson['ping']['jitter']
|
||||
latencyavg=respjson['ping']['latency']
|
||||
minlatency=respjson['ping']['low']
|
||||
maxlatency=respjson['ping']['high']
|
||||
result = addinfluxrecord(downspeed,upspeed,pktloss,jitter,latencyavg,minlatency,maxlatency)
|
||||
print(result)
|
||||
time.sleep(300)
|
Reference in New Issue
Block a user