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
|
||||
|
||||
import speedtest
|
||||
import os
|
||||
import json
|
||||
from influxdb import InfluxDBClient
|
||||
from time import time, sleep
|
||||
|
||||
serverip = "192.168.0.13"
|
||||
serverport = 8086
|
||||
serverdatabase = "telegraf"
|
||||
servernickname = 'Yoo01pn.ddns.net'
|
||||
serverip = os.environ['INFLUX_IP']
|
||||
serverport = os.environ['INFLUX_PORT', 8086]
|
||||
serverdatabase = os.environ['INFLUX_DB', 'telegraf']
|
||||
servernickname = os.environ['NICKNAME', 'SERV01'] # Name to put under in influx
|
||||
server = os.environ['SPEEDTEST_SERVER','19249']
|
||||
|
||||
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
|
||||
servers = [servertag] # If you want to test against a specific server eg. ['13030'] or [] for closest server
|
||||
threads = 16
|
||||
# Choose the amount of threads to use for the test
|
||||
test = speedtest.Speedtest()
|
||||
test.get_servers(servers)
|
||||
@ -33,14 +35,14 @@ def speed(): # Actual Speedtest using speedtest-cli
|
||||
print(results["share"]) # Show share link
|
||||
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_where = 'select Int_value from cpu_load_short where host=$host;'
|
||||
bind_params = {'host': servernickname}
|
||||
testdata = speed()
|
||||
json_body = [
|
||||
{
|
||||
"measurement": "PythonSpeedTest",
|
||||
"measurement": "speedtest-influx-docker",
|
||||
"tags": {
|
||||
"host": servernickname,
|
||||
},
|
||||
@ -58,7 +60,7 @@ def uploadInfluxdata(host='192.168.0.13', port=8086): # Main upload section
|
||||
|
||||
while True:
|
||||
print("Running Test")
|
||||
uploadInfluxdata()
|
||||
uploadInfluxdata(serverip, serverport)
|
||||
sleep(600)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user