I am speed
This commit is contained in:
commit
94be2715a2
BIN
__pycache__/influxlite.cpython-38.pyc
Normal file
BIN
__pycache__/influxlite.cpython-38.pyc
Normal file
Binary file not shown.
35
influxlite.py
Normal file
35
influxlite.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
## Sean Corrigan 2020
|
||||||
|
# Easy lite API to use in my other scripts
|
||||||
|
# to send data to my influx server.
|
||||||
|
|
||||||
|
from influxdb import InfluxDBClient
|
||||||
|
|
||||||
|
def createFields(datadict):
|
||||||
|
data = []
|
||||||
|
for i,v in datadict.items():
|
||||||
|
data.append("\"{}\": {}\n".format(i,v))
|
||||||
|
return ''.join(data)
|
||||||
|
|
||||||
|
|
||||||
|
def uploadData(host, database, measurementname, datadict, nickname = 'pythontestscript', port=8086): ## Push data to Influx server
|
||||||
|
fields = createFields(datadict)
|
||||||
|
bind_params = {'host': servernickname}
|
||||||
|
|
||||||
|
json_body = [
|
||||||
|
{
|
||||||
|
"measurement": measurementname,
|
||||||
|
"tags": {
|
||||||
|
"host": servernickname,
|
||||||
|
},
|
||||||
|
|
||||||
|
"fields": {
|
||||||
|
createFields(datadict),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
client = InfluxDBClient(host, port, database) # Init connection to Influx Server
|
||||||
|
client.write_points(json_body) # Write Speedtest results
|
||||||
|
|
||||||
|
if if __name__ == "__main__":
|
||||||
|
uploadData(host='192.168.0.13', database='telegraf', )
|
||||||
58
speedbeta.py
Normal file
58
speedbeta.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Sean Corrigan 2020
|
||||||
|
# Script sends data to influx in bits/sec
|
||||||
|
|
||||||
|
import speedtest
|
||||||
|
import json
|
||||||
|
from influxdb import InfluxDBClient
|
||||||
|
|
||||||
|
serverip = "192.168.0.13"
|
||||||
|
serverport = 8086
|
||||||
|
serverdatabase = "telegraf"
|
||||||
|
servernickname = 'Yoo01pn.ddns.net'
|
||||||
|
|
||||||
|
def speed(): # Actual Speedtest using speedtest-cli
|
||||||
|
servers = ['19249'] # If you want to test against a specific server eg. ['13030'] or [] for closest 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()
|
||||||
|
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
result["UploadSpeed"] = results["upload"]
|
||||||
|
result["DownloadSpeed"] = results["download"]
|
||||||
|
result["Ping"] = results["ping"]
|
||||||
|
|
||||||
|
print(results["share"]) # Show share link
|
||||||
|
return(result)
|
||||||
|
|
||||||
|
def uploadInfluxdata(host='192.168.0.13', port=8086): # Main upload section
|
||||||
|
query = 'select Float_value from cpu_load_short;'
|
||||||
|
query_where = 'select Int_value from cpu_load_short where host=$host;'
|
||||||
|
bind_params = {'host': servernickname}
|
||||||
|
testdata = speed()
|
||||||
|
json_body = [
|
||||||
|
{
|
||||||
|
"measurement": "PythonSpeedTest",
|
||||||
|
"tags": {
|
||||||
|
"host": servernickname,
|
||||||
|
},
|
||||||
|
|
||||||
|
"fields": {
|
||||||
|
"Upload": testdata["UploadSpeed"],
|
||||||
|
"Download": testdata["DownloadSpeed"],
|
||||||
|
"Ping": testdata["Ping"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
client = InfluxDBClient(host, port, database = serverdatabase) # Init connection to Influx Server
|
||||||
|
client.write_points(json_body) # Write Speedtest results
|
||||||
|
|
||||||
|
uploadInfluxdata()
|
||||||
Loading…
Reference in New Issue
Block a user