handle packetloss

This commit is contained in:
Josh 2020-07-21 20:26:27 -04:00
parent 3b9ccf5c2e
commit 14f0c8990d

View file

@ -7,6 +7,7 @@ from influxdb import InfluxDBClient
# InfluxDB Settings # InfluxDB Settings
DB_ADDRESS = os.environ.get('INFLUX_DB_ADDRESS') DB_ADDRESS = os.environ.get('INFLUX_DB_ADDRESS')
print(os.environ.get('INFLUX_DB_PORT'))
DB_PORT = int(os.environ.get('INFLUX_DB_PORT')) DB_PORT = int(os.environ.get('INFLUX_DB_PORT'))
DB_USER = os.environ.get('INFLUX_DB_USER') DB_USER = os.environ.get('INFLUX_DB_USER')
DB_PASSWORD = os.environ.get('INFLUX_DB_PASSWORD') DB_PASSWORD = os.environ.get('INFLUX_DB_PASSWORD')
@ -28,7 +29,11 @@ def init_db():
DB_DATABASE) # Create if does not exist. DB_DATABASE) # Create if does not exist.
else: else:
influxdb_client.switch_database(DB_DATABASE) # Switch to if does exist. influxdb_client.switch_database(DB_DATABASE) # Switch to if does exist.
def pkt_loss(data):
if data['packetLoss']:
return data['packetLoss']
else:
return 0
def format_for_influx(cliout): def format_for_influx(cliout):
data = json.loads(cliout) data = json.loads(cliout)
@ -66,7 +71,7 @@ def format_for_influx(cliout):
'measurement': 'packetLoss', 'measurement': 'packetLoss',
'time': data['timestamp'], 'time': data['timestamp'],
'fields': { 'fields': {
'packetLoss': int(data['packetLoss']) 'packetLoss': pkt_loss(data)
} }
} }
] ]