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:

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?).


Welcome to the community!

Yes, this is possible in Telegraf and is called metric filtering, see here in the docs:

Configuring Telegraf | Telegraf 1.21 Documentation

Here is a simple example.

# other plugin configs...
measurement_name = "mqtt_1"

# other plugin configs...
measurement_name = "mqtt_2"

# other plugin configs...
namepass = ["mqtt_1"]

# 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: