Multiple mqtt_consumer inputs - how to configure?

noob’s question:

i’m trying to configure telegraf to fetch data from two different mqtt servers, outputting to seperate databases. i found this, which i guess should handle the outputs:

but i can’t find any examples of how to configure the inputs - if it’s possible that way at all…

i assumed that cloning the whole block from [[inputs.mqtt_consumer]] and adapting the values below that should do the trick - but i’m getting a parse error on the second [[inputs.mqtt_consumer]].

any help appreciated.

thanks.

Hi @markusk,

I believe it would be a lot simpler to run 2 telegraf processes on your machine, each configured with an input and output.

Do you have any constraints that require this to be a single telegraf instance?

well, no real constraints i guess - though running in a docker container on a rather weak NAS…

but gotta question the modular concept of plugins, if i still need to multiply monolithic constructs … or is all this just “not there” yet?

thanks.

Assigning inputs to outputs is certainly something that we’re happy to see implemented, but with 2.x so close; it’s going to need to be community contribution for now.

1 Like

You can do this with a single Telegraf, there are very few reasons to run Telegraf more than once on a system. Your strategy is the right one, just have multiple mqtt_consumer tables, can you show your config and the parse error you are seeing?

thanks … quickly gave it another try before heading to bed …

indeed telegraf started up with two mqtt-inputs defined - without adding a tag … a quick search revealed that i had it put in the wrong place, directly after the opening [[inputs.mqtt_consumer]] though it should go to the end …
unfortunately i turned off the device (it’s at another house) sending the data earlier today so i can’t check if it’s really working as expected, but i’m confident now that it’s at least starting up properly…

thanks,
markus.

How do you configure each mqtt input to write to a different output?

check this out: telegraf/CONFIGURATION.md at master · influxdata/telegraf · GitHub

last example. think i got the hang of it now with this.

essentially you’re using the tags to mark/label/flag metrics and then either pass it to a given output or not by filtering/selecting.

so my second mqtt-input got a

[inputs.mqtt_consumer.tags]
    influxdb_database = "something2identify"

(at the end - this seems to be important.)

the first influxDB-output ignores all metrics that have any tag of type influxdb_database by

[outputs.influxdb.tagdrop]
    influxdb_database = ["*"]

so our data from the second mqtt-input is ignored/dropped.

… and the second influxDB-ouput first is instructed to not save the tag in the db (as one likely one won’t need it - as it’s always the same anyways)

tagexclude = ["influxdb_database"]

and then to save the metrics which have this tag

  [ouputs.influxdb.tagpass]
    influxdb_database = ["something2identify"]