I am trying to feed a MQTT-Message in json_v2 format which contains an array of integers into InfluxDB. Currently it just takes the last number of the array and all others are lost.
Hello @Nils_Franke,
Welcome!
So this documentation might be helpful.
I would try .object and maybe the prepend too.
I think that should get you all of your metrics. Though I wonder if/bet that they’re being overwritten. ’
Yup just confirmed with the --test flag and printed lines to stdout
You would need to add a timestamp to each energy value. or make energy a tag (which is not ideal).
You can add a timestamp with the execd processor plugin.
Your python script for example could look like:
import sys
import json
from datetime import datetime, timedelta
def add_timestamps(data):
base_time = datetime.now()
if 'energy' in data:
for i, value in enumerate(data['energy']):
data['energy'][i] = {
"value": value,
"timestamp": (base_time + timedelta(seconds=i)).isoformat() + "Z"
}
return data
# Read JSON from stdin
input_data = json.load(sys.stdin)
# Process the data
output_data = add_timestamps(input_data)
# Write JSON to stdout
json.dump(output_data, sys.stdout)
and your add_timestamps.py would change the timestamps slightly.
Or you could make 3 field keys this is the better solution i’m guessing. Still the approach could be the same. Youd just change the logic in your python script.
thank you for your quick answers. I actually came along these posts before reaching out to you and they are not very helpful to be honest. Not least because it says “Closed, solution found” without pointing out the solution. Every example, also on other webpages, shows only line protocol outputs, but we want to have it being shown correctly in the Influx->Data Explorer-> “Simple Table”. Can you give me a doc or a step-by-step guide on this one?