I am encountering an issue in which my data is not being written to my InfluxDB server. I’m guessing that my issue may be a result of not specifying WriteOptions (batch size, flush interval etc.), but I couldn’t quite get it to work even with modifying the defualt values.
Code snippet:
print("Conduct connection Health Check prior to parse: {}".format(client.health()))
write_api = client.write_api()
#query_api = client.query_api()
for element in data: # element are the entries in the TOP LEVEL JSON data object
dataInfluxDB=[] # List for data batch write - should not exceed 5000 points
# If JSON Field value is a Nested JSON
if (isinstance(data[element], dict)):
checkDict(data[element], element)
# This loop will go through every expiration date and strike price in the putExpDateMap and then callExpDateMap
# A batch write of data will occur in this loop to package all the "PUT" data, send and
print(dataInfluxDB)
write_api.write(bucket=bucket, org='-', record=[dataInfluxDB])
print('Should have written this data')
# If JSON Field value is a string, float or integer. This will print the immediate key:value data in the first level object
elif (isinstance(data[element], (str, float, int, type, type(None)))):
pass
print("Result of connection close is: {}".format(client.close()))
print(time.process_time()-start) # Report total time
Terminal Output:
Conduct connection Health Check prior to parse: {'checks': [],
'commit': None,
'message': 'ready for queries and writes',
'name': 'influxdb',
'status': 'pass',
'version': '1.8.4'}
['aapl,contract=PUT strikePrice=30.0,bid=0.0,ask=0.01,last=0.01,mark=0.01 1615582795743', 'aapl,contract=PUT strikePrice=35.0,bid=0.0,ask=0.01,last=0.01,mark=0.0 1615924799542']
Should have written this data
['aapl,contract=CALL strikePrice=30.0,bid=90.9,ask=91.15,last=90.85,mark=91.03 1615582799923', 'aapl,contract=CALL strikePrice=35.0,bid=90.5,ask=90.65,last=88.25,mark=90.58 1615924799823']
Should have written this data
Result of connection close is: None
0.0
I’m doing this for a school based project and my goal is to perform batch writes, as you can see above, in the line protocol format.I referenced the write API examples, but still have had no luck in getting the above to work.
In my example I’m only sending (2) data points in (1) batch, but this is simply for testing purposes. In the real application, the batch sizes would probably be closer to 1000-2000 per write; (2) writes total, one for CALL and one for PUT.
Any feedback would be highly appreciated.