Telegraf json input not saving all object in array

I am sending json arrays to telegraf like such:

[
  {
    "label" : "truck_back",
    "class_id" : 0,
    "confidence" : 0.99936622381210327,
    "bbox_left" : 149.44915771484375,
    "bbox_top" : 51.641281127929688,
    "bbox_width" : 204.45062255859375,
    "bbox_height" : 386.286865234375
  },
  {
    "label" : "external_valve_open",
    "class_id" : 1,
    "confidence" : 0.44154483079910278,
    "bbox_left" : 225.6270751953125,
    "bbox_top" : 175.45341491699219,
    "bbox_width" : 52.367267608642578,
    "bbox_height" : 52.37811279296875
  }
]

and here is my telegraf config:

[[inputs.amqp_consumer]]
brokers = ["amqp://rabbitmq:5672"]
queue = "object-detection"
prefetch_count = 500
data_format = "json"
json_string_fields = ["label"]

It appears only one of the objects is being saved to influx (the last one in the list).

Is there a way to save multiple records with the same timestamp with the telegraf json input?

Thank you.

I put your json snippet exactly as it is into a file jsonarray.json and ran this telegraf conf:

[[inputs.file]]
  files = ["jsonarray.json"]
  data_format = "json"
  json_string_fields = ["label"]

[[outputs.file]]  # only for debugging
  files = ["jsonarray.out"]
  influx_sort_fields = true

Got this output:

file bbox_height=386.286865234375,bbox_left=149.44915771484375,bbox_top=51.64128112792969,bbox_width=204.45062255859375,class_id=0,confidence=0.9993662238121033,label="truck_back" 1616764996000000000
file bbox_height=52.37811279296875,bbox_left=225.6270751953125,bbox_top=175.4534149169922,bbox_width=52.36726760864258,class_id=1,confidence=0.4415448307991028,label="external_valve_open" 1616764996000000000

Works on my machine :thinking: :wink:

Edit1:

But wait, it could be that this row is overwritten in InfluxDB itself, because it is the same timestamp and the same set of fields.

Edit2:

Try it with a tag instead of a field, this could work:

  data_format = "json"
  tag_keys = ["label"]
1 Like

@Franky1 Thank you! So many good answers.