I have a few MQTT sources, some under my control, other “off the shelf”.
Typically, I want the various MQTT source data to land in its dedicated influxdb database.
In telegraf.conf, I use:
[[outputs.influxdb]]
urls = [“http://influxdb:8086 ”]
database = “telegraf”
database_tag = “database”
For the MQTT sources which I have control, I add a key:value - database:databasename1.
For MQTT sources which I don’'t have control, all ends up in database telegraf.
Is there anyway to fix this? Is there a way to specify per [[inputs.mqtt_consumer]] input (which subscribes to a specific MQTT topic) the influxdb database (or insert an additional tag database:value?).
Thanks
Hans
Welcome to the community!
Yes, this is possible in Telegraf and is called metric filtering , see here in the docs:
https://docs.influxdata.com/telegraf/v1/configuration/
Here is a simple example.
[[inputs.mqtt_consumer]]
# other plugin configs...
measurement_name = "mqtt_1"
[[inputs.mqtt_consumer]]
# other plugin configs...
measurement_name = "mqtt_2"
[[outputs.influxdb]]
# other plugin configs...
namepass = ["mqtt_1"]
[[outputs.influxdb]]
# other plugin configs...
namepass = ["mqtt_2"]
1 Like
Thanks, trigger email got lost in spam; I will give it a try asap!
Or maybe try this even better solution:
There is a better way to do that, use the bucket_tag option of the InflxDB2 output (docs here )
it allows you to specify the “routing” by using a tag value
Here is a sample using your current config
[[inputs.mqtt_consumer]]
servers = ["tcp://e_mqtt:1883"]
topics = [
"Y/Schlafzimmer/power/SENSOR",
]
data_format = "json"
[inputs.mqtt_consumer.tags]
destination = "Ybucket"
[[inputs.mqtt_consumer]]
servers = ["tcp://e_mqtt:1883"]
topics = [
"PowerMeter/001/power/SENSOR",
"…