Mqtt json can't post to influxdb

json input:

{
  "id": 383853,
  "temp": 24.2,
  "ph": 2.89,
  "conductivity": 16.57,
  "speed": 540,
  "substrate_id": "B02312023091301280",
  "date_time": 1700207501
}

telegraf config:

[[inputs.mqtt_consumer]]
  servers = ["tcp://192.168.0.129:1883"]
  topics = [
    "mqtt/csv_test",
  ]
  qos = 2
  client_id = "XX"
  username = "XX"
  password = "XX"
  data_format = "json_v2"
  [[inputs.mqtt_consumer.json_v2]]
    measurement_name = "csv_file_test"
    timestamp_path = "date_time"
    timestamp_format = "unix"
    timestamp_timezone = "Asia/Shanghai"
    [[inputs.mqtt_consumer.json_v2.field]]
      path = "id"
    [[inputs.mqtt_consumer.json_v2.field]]
      path = "temp"
    [[inputs.mqtt_consumer.json_v2.field]]
      path = "ph"
    [[inputs.mqtt_consumer.json_v2.field]]
      path = "conductivity"
    [[inputs.mqtt_consumer.json_v2.field]]
      path = "speed"
    [[inputs.mqtt_consumer.json_v2.field]]
      path = "substrate_id"
      type = "string"
[[processors.printer]]

Logs from Telegraf

2023-11-23T03:01:44Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2023-11-23T03:01:54Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383844,temp=24.1,ph=2.91,conductivity=16.57,speed=540,substrate_id="A02312023111002040" 1700206986000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383845,temp=24.1,ph=2.91,conductivity=16.57,speed=540,substrate_id="A02312023111008070" 1700207038000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383846,temp=24.1,ph=2.91,conductivity=16.57,speed=540,substrate_id="A02312023111008060" 1700207102000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383847,temp=24.1,ph=2.91,conductivity=16.57,speed=540,substrate_id="A02312023111003330" 1700207154000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383848,temp=24.1,ph=2.91,conductivity=16.57,speed=540,substrate_id="A02312023111003380" 1700207218000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383849,temp=24.1,ph=2.91,conductivity=16.57,speed=540,substrate_id="A02312023111007040" 1700207270000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383850,temp=24.1,ph=2.9,conductivity=16.57,speed=540,substrate_id="NULL" 1700207333000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383851,temp=24.2,ph=2.9,conductivity=16.57,speed=540,substrate_id="A02312023111003050" 1700207385000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383852,temp=24.1,ph=2.89,conductivity=16.57,speed=540,substrate_id="A02312023111003060" 1700207449000000000
csv_file_test,host=895ee07f3228,topic=mqtt/csv_test id=383853,temp=24.2,ph=2.89,conductivity=16.57,speed=540,substrate_id="B02312023091301280" 1700207501000000000
2023-11-23T03:02:04Z D! [outputs.influxdb_v2] Wrote batch of 10 metrics in 4.218801ms
2023-11-23T03:02:04Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2023-11-23T03:02:14Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics

Expected behavior

This data will post in influxdb

Actual behavior

The bucket not receive any data

Steps to reproduce

  1. if i don’t config the timestamp_path = "data_time", all data will post in influxdb
  2. i try use data_format = json, config json_time_key = "data_time", the data also don’t post to influxdb

System info

Ubuntu 22.04, Influxdb 2.7.4(Docker), Telegraf(Alpine Docker)

PS: also in github:mqtt json can't post to influxdb · Issue #14336 · influxdata/telegraf · GitHub

Strange. The config looks right based on the data snippet.

Is any errors or warnings getting logged on the influxdb end? That would be where I’d look next…

https://docs.influxdata.com/influxdb/v2/admin/logs/#configure-your-log-level

1 Like

@FixTestRepeat Thank you so much!

1 Like