简体   繁体   中英

Telegraf MQTT consumer with multiple topics and json data

We use Telegraf to connect to an MQTT broker and subscribe to several topics. The data send through is all in JSON, but with different configurations.

[[inputs.mqtt_consumer]]
  name_override = "devices"
  topics = [
    "devices/+/control",
  ]

  servers = ["${MQTT_SERVER_URL}"]

  tagexclude = ["host", "topic"]

  data_format = "json"
  json_name_key = ""
  json_time_key = "ts"
  json_time_format = "unix_ms"
  tag_keys = ["site"]
  json_string_fields = ["mode", "is_online"]

Do we need multiple different mqtt_consumer input plugins for different json structures, or can that be handled with the topic parser somehow? I'm struggling to find real world examples for this kind of setup.

Do we need multiple different mqtt_consumer input plugins for different json structures,

It depends on just how different the structure is. If the JSON is relatively flat, then you may not, but if it has different objects defined, I would suggest you use different inputs. Generally, if you have different structures then you probably have different tags and your ultimate time series metric will be different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM