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.