Telegraf...specify influxdb database per mqtt input?

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: