Added envirometnt variables
This commit is contained in:
parent
725d46b02b
commit
eb186c6ed1
20
main.py
20
main.py
@ -2,18 +2,20 @@
|
|||||||
# Script sends data to influx in bits/sec
|
# Script sends data to influx in bits/sec
|
||||||
|
|
||||||
import speedtest
|
import speedtest
|
||||||
|
import os
|
||||||
import json
|
import json
|
||||||
from influxdb import InfluxDBClient
|
from influxdb import InfluxDBClient
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
|
|
||||||
serverip = "192.168.0.13"
|
serverip = os.environ['INFLUX_IP']
|
||||||
serverport = 8086
|
serverport = os.environ['INFLUX_PORT', 8086]
|
||||||
serverdatabase = "telegraf"
|
serverdatabase = os.environ['INFLUX_DB', 'telegraf']
|
||||||
servernickname = 'Yoo01pn.ddns.net'
|
servernickname = os.environ['NICKNAME', 'SERV01'] # Name to put under in influx
|
||||||
|
server = os.environ['SPEEDTEST_SERVER','19249']
|
||||||
|
|
||||||
def speed(): # Actual Speedtest using speedtest-cli
|
def speed(): # Actual Speedtest using speedtest-cli
|
||||||
servers = ['19249'] # If you want to test against a specific server eg. ['13030'] or [] for closest server
|
servers = [servertag] # If you want to test against a specific server eg. ['13030'] or [] for closest server
|
||||||
threads = 4
|
threads = 16
|
||||||
# Choose the amount of threads to use for the test
|
# Choose the amount of threads to use for the test
|
||||||
test = speedtest.Speedtest()
|
test = speedtest.Speedtest()
|
||||||
test.get_servers(servers)
|
test.get_servers(servers)
|
||||||
@ -33,14 +35,14 @@ def speed(): # Actual Speedtest using speedtest-cli
|
|||||||
print(results["share"]) # Show share link
|
print(results["share"]) # Show share link
|
||||||
return(result)
|
return(result)
|
||||||
|
|
||||||
def uploadInfluxdata(host='192.168.0.13', port=8086): # Main upload section
|
def uploadInfluxdata(host, port): # Main upload section
|
||||||
query = 'select Float_value from cpu_load_short;'
|
query = 'select Float_value from cpu_load_short;'
|
||||||
query_where = 'select Int_value from cpu_load_short where host=$host;'
|
query_where = 'select Int_value from cpu_load_short where host=$host;'
|
||||||
bind_params = {'host': servernickname}
|
bind_params = {'host': servernickname}
|
||||||
testdata = speed()
|
testdata = speed()
|
||||||
json_body = [
|
json_body = [
|
||||||
{
|
{
|
||||||
"measurement": "PythonSpeedTest",
|
"measurement": "speedtest-influx-docker",
|
||||||
"tags": {
|
"tags": {
|
||||||
"host": servernickname,
|
"host": servernickname,
|
||||||
},
|
},
|
||||||
@ -58,7 +60,7 @@ def uploadInfluxdata(host='192.168.0.13', port=8086): # Main upload section
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
print("Running Test")
|
print("Running Test")
|
||||||
uploadInfluxdata()
|
uploadInfluxdata(serverip, serverport)
|
||||||
sleep(600)
|
sleep(600)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user