Influxdb_v2 Output to different buckets doesn't work

Hello !

We are trying to output our incoming data to different buckets using tagpass but it doesn’t seem to work. Everything is working inside containers. A Telegraf container is fetching data from a Mosquitto container and tries to send it to the influx (version 2.1.1) container.

We want to send:
input 1 → bucket 1
input 2 → bucket 2
input 3 → bucket 3

How can we get it to work? Do we need a default bucket?

The code:

[agent]
 interval = "20ms"
 round_interval = true
 precision = "rfc3339"

#input 1 Y
[[inputs.mqtt_consumer]]
  servers = ["tcp://e_mqtt:1883"]
  topics = [
  "Y/Schlafzimmer/power/SENSOR",
  ]
  [inputs.mqtt_consumer.tags]
    tag = "Y"

  data_format = "json"

#input 2 X
[[inputs.mqtt_consumer]]
  servers = ["tcp://e_mqtt:1883"]
  topics = [
  "X/001/pulse/RESULT",
  "X/002/pulse/RESULT",
  "X/003/pulse/RESULT",
  "X/004/pulse/RESULT",
  "X/005/pulse/RESULT",
  "X/006/pulse/RESULT",
  "X/007/pulse/RESULT",
  "X/008/pulse/RESULT",
  "X/009/pulse/RESULT",
  "X/010/pulse/RESULT",
  "X/011/pulse/RESULT",
  "X/012/pulse/RESULT",
  "X/013/pulse/RESULT",
  "X/014/pulse/RESULT",
  "X/015/pulse/RESULT",
  ]
    [inputs.mqtt_consumer.tags]
        tag = "X"

  data_format = "json"

#input 3 Z
[[inputs.mqtt_consumer]]
  servers = ["tcp://e_mqtt:1883"]
  topics = [
  "PowerMeter/001/power/SENSOR",
  "PowerMeter/002/power/SENSOR",
  ]
    [inputs.mqtt_consumer.tags]
        tag = "Z"

  data_format = "json"

#output für 1 Y
[[outputs.influxdb_v2]]
  urls = ["http://e_influxdb:8086"]
  token = "ULw91qCCOyBrVqwWyNdmy8ckzmJhjbrZMhgf57XmXp4elkFsf-atwpQ=="
  organization = "my-org"
  bucket = "Ybucket"
  [outputs.influxdb_v2.tagpass]
    tag = ["Y"]


#output für 2 X
[[outputs.influxdb_v2]]
  urls = ["http://e_influxdb:8086"]
  token = "ULw91qCCOyBrVqwWyNdmy8ckzmJhjbrZMhgf57XmXp4elkFsf-atwpQ=="
  organization = "my-org"
  bucket = "Xbucket"
  tagexclude =["tag"]
  [outputs.influxdb_v2.tagpass]
    tag = ["X"]

#output für 3 Z
[[outputs.influxdb_v2]]
  urls = ["http://e_influxdb:8086"]
  token = "ULw91qCCOyBrVqwWyNdmy8ckzmJhjbrZMhgf57XmXp4elkFsf-atwpQ=="
  organization = "my-org"
  bucket = "Zbucket"
  tagexclude =["tag"]
  [outputs.influxdb_v2.tagpass]
    tag = ["Z"]

Thank you!

I would use namepass for the metric filtering:

Configuring Telegraf | Telegraf 1.21 Documentation

Here is a simple example:

Telegraf...specify influxdb database per mqtt input? - #2 by Franky1

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",
  "PowerMeter/002/power/SENSOR",
  ]
  data_format = "json"
    [inputs.mqtt_consumer.tags]
       destination = "Zbucket"


[[outputs.influxdb_v2]]
  urls = ["http://e_influxdb:8086"]
  token = "ULw91qCCOyBrVqwWyNdmy8ckzmJhjbrZMhgf57XmXp4elkFsf-atwpQ=="
  organization = "my-org"

  bucket_tag = "destination"
  ## If true, the bucket tag will not be added to the metric.
  exclude_bucket_tag = true
2 Likes

Thank you!!

Everything is working out now! Thanks a lot!