Hello, I am trying to configure Telegraf with mqtt_consumer
and data_format = "json_v2"
and topic_parsing
.
I tried many different configurations, as far as I could figure out was, that the topic_parsing
configuration is the problem.
This configuration works:
[[inputs.mqtt_consumer]]
servers = ["tcp://rabbitmq:1883"]
topics = [
"telegraf/stocks"
]
username = "xxx"
password = "xxx"
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
measurement_name = "stocks"
[[inputs.mqtt_consumer.json_v2.object]]
path = "@this"
tags = ["isin", "name", "unit"] # can list all tags
[inputs.mqtt_consumer.json_v2.object.fields]
val = "float"
With this MQTT-message: (topic = telegraf/stocks
)
{
"isin": "TEST",
"name": "TestStock",
"unit": "EUR",
"date": "2022-03-01",
"val": 123.456789
}
If I remove the measurement_name
from the config and try to parse the topic, in order to set the measurement name dynamically I get the following error:
[[inputs.mqtt_consumer]]
servers = ["tcp://rabbitmq:1883"]
topics = [
"telegraf/stocks"
]
username = "xxx"
password = "xxx"
[[inputs.mqtt_consumer.topic_parsing]]
topic = "telegraf/+"
measurement = "_/measurement"
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
[[inputs.mqtt_consumer.json_v2.object]]
path = "@this"
tags = ["isin", "name", "unit"] # can list all tags
[inputs.mqtt_consumer.json_v2.object.fields]
val = "float"
Error message:
2022-04-02T12:09:47Z E! [inputs.mqtt_consumer] Error in plugin: metric parse error: expected tag at 1:34: "{\"isin\":\"TEST\",\"name\":\"TestStock\",\"unit\":\"EUR\",\"date\":\"2022-03-01\",\"val\":123.456789}"
I tried to look at the source code at GitHub, but could not figure out how to configure the topic_parsing
in order to work properly.
Can anyone give me a hint on what is wrong with my config. Or is this maybe a bug?
Thanks in advance and,
Best regards.