Parsing JSON to InfluxDB - timestamp not picked up (json_v2)

I would like to parse the following JSON with Telegraf into InfluxDB using json_v2. The JSON contains datetime information, but I cannot figure out how to set up the telegraf configuration to make the datetime information to be picked up.

I followed the examples on https://www.influxdata.com/blog/how-parse-json-telegraf-influxdb-cloud/

Here a snippet of my JSON. You can find the typical full JSON output here: https://gist.githubusercontent.com/anjoweichbrodt/69507cc5e93e0194aa92843863596340/raw/cbaaa3e0ec812638d46cb79d4b9654a76ae3eed6/json_output

[
  {
    "Caption": "mote temperature",
    "Mote": "0x70",
    "dt": 1598019166,
    "Value": 24.06,
    "Unit": "°C",
    "SensorID": "1339399",
    "Heading": "SM_TEMP (Temperature)"
  },
  {
    "Caption": "operating T",
    "Mote": "0x70",
    "dt": 1598009240,
    "Value": -325.79,
    "Unit": "°C",
    "SensorID": "1339527",
    "Heading": "SM_TEMP (Temperature)"
  },
  {
    "Caption": "mote temperature",
    "Mote": "0x72",
    "dt": 1597085475,
    "Value": 23.06,
    "Unit": "°C",
    "SensorID": "1339911",
    "Heading": "SM_TEMP (Temperature)"
  }
]

Following my telegraf configuration:

[[inputs.http]]
  urls = ["http://flask-app:5000/"]
  tagexclude = ["url", "host"]
  data_format = "json_v2"
  [[inputs.http.json_v2]]
    [[inputs.http.json_v2.object]]
      path = "#.@this"
      tags = ["Mote","Heading","SensorID","Caption"]  
      timestamp_key = "dt"
      timestamp_format = "unix"

Hi!

Thanks for including a config and an example json. It makes it much easier to try it out.

I was able to reproduce with an older Telegraf, v1.20.2, however, I was unable to reproduce on master:

2022-01-12T17:12:58Z I! Starting Telegraf 1.22.0-c2c15e8b
...
file,Caption=mote\ temperature,Heading=SM_TEMP\ (Temperature),Mote=0x70,SensorID=1339399,host=ryzen Value=24.06,Unit="°C" 1598019166000000000
file,Caption=operating\ T,Heading=SM_TEMP\ (Temperature),Mote=0x70,SensorID=1339527,host=ryzen Value=-325.79,Unit="°C" 1598009240000000000
file,Caption=mote\ temperature,Heading=SM_TEMP\ (Temperature),Mote=0x72,SensorID=1339911,host=ryzen Value=23.06,Unit="°C" 1597085475000000000

What version of Telegraf are you using? Could you try the latest or one of our nightlies?

Thanks!

2 Likes

I also tried it with Telegraf 1.21.2 for Win64, and the above configuration from @anjoweichbrodt worked fine.

[[inputs.http]]
  urls = ["https://gist.githubusercontent.com/anjoweichbrodt/69507cc5e93e0194aa92843863596340/raw/cbaaa3e0ec812638d46cb79d4b9654a76ae3eed6/json_output"]
  tagexclude = ["url", "host"]
  data_format = "json_v2"
  [[inputs.http.json_v2]]
    [[inputs.http.json_v2.object]]
      path = "#.@this"
      tags = ["Mote","Heading","SensorID","Caption"]
      timestamp_key = "dt"
      timestamp_format = "unix"

[[outputs.file]]  # only for debugging
  files = ["flask.out"]
  influx_sort_fields = true
2 Likes

Hi,

Many thanks for your quick help! I was struggling with this for some time, and indeed didn’t realize that I had not updated my Telegraf Docker image for some time.

I was using Telegraf 1.19.3. Updating to Telegraf 1.21.2 resolved my issue.

2 Likes