I’m trying to parse a JSON file received by a MQTT Broker (Mosquitto) connection to feed an already create database. I’m using telegraf and influxDB on a VM(Ubuntu 18.04). I can see the value from mqtt_consumer
inside the database, however, it is a not well parsed JSON where variable and data are shifted.
This is the JSON file:
{ "message":{ "basic_container":{ "confidence":{ "altitude":15, "semi_major_confidence":0, "semi_major_orientation":0, "semi_minor_confidence":0 }, "reference_position":{ "altitude":0, "latitude":414066546, "longitude":21750345 }, "station_type":5 }, "generation_delta_time":45315, "high_frequency_container":{ "confidence":{ "curvature":7, "heading":127, "longitudinal_acceleration":102, "speed":127, "vehicle_length":4, "yaw_rate":8 }, "curvature":1023, "curvature_calculation_mode":2, "drive_direction":2, "heading":3601, "longitudinal_acceleration":161, "speed":500, "vehicle_length":1023, "vehicle_width":62, "yaw_rate":32767 }, "protocol_version":2, "station_id":224 }, "origin":"on_board_application", "source_uuid":"cttc_car_224", "type":"cam", "version":"1.0.0", "timestamp":1605886891388 }
The part of telegraf.conf is this:
[[inputs.mqtt_consumer]] servers = [“tcp://*.*.*.*:1883”] topics = [ “one/#”, “two#”, ] qos = 0 connection_timeout = "30s" max_undelivered_messages = 1000 persistent_session = false json_query = "" data_format = "json" tag_keys = ["timestamp"]
I’ve tried to get just a simple tag “station_type” but it is not shown at the influx measurements.
This is the influxdb part:
[[outputs.influxdb]] urls = ["http://127.0.0.1:8086"] database = "v2x_manager" write_consistency = "any" timeout = "5s"
This is the influx output
VirtualBox:~$ influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3use v2x_manager
Using database v2x_manager
show measurements
name: measurements
namecpu
disk
diskio
kernel
mem
processes
swap
system
This example only shows how to get the value of timestamp
, however, I need to get all the variable values. How can I do it?