Telegraf UDP Listener with two sockets and two buckets

Hello everyone,

We have a Telegraf UDP Listener with two sockets. Attached is the config:

[agent]
interval = “10s”
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = “0s”
flush_interval = “10s”
flush_jitter = “0s”
precision = “”
hostname = “”
omit_hostname = false

[[inputs.socket_listener]]
service_address = “udp://0.0.0.0:8092”

[[outputs.influxdb_v2]]
urls = [“https://url.de:8086”]
token = “token”
organization = “org”
bucket = “bucket_1”

[[inputs.socket_listener]]
service_address = “udp://0.0.0.0:8093”

[[outputs.influxdb_v2]]
urls = [“https://url.de:8086”]
token = “token”
organization = “org”
bucket = “bucket_2”

If data is received by udp://0.0.0.0:8092, it should be sent to bucket_1.
If data is received on udp://0.0.0.0:8093, it should be sent to bucket_2.

Currently, the data is sent to both udp://0.0.0.0:8092 and udp://0.0.0.0:8093 to both buckets.

Can you help us?

@cunnect you can route metrics using tags which should work in your case by just adding a bucket tag and use the bucket_tag option of a single InfluxDBv2 output like

[agent]
  ...

[[inputs.socket_listener]]
  service_address = "udp://0.0.0.0:8092"
  [inputs.socket_listener.tags]
    bucket = "bucket1"

[[inputs.socket_listener]]
  service_address = "udp://0.0.0.0:8093"
  [inputs.socket_listener.tags]
    bucket = "bucket2"

[[outputs.influxdb_v2]]
  urls = ["https://url.de:8086"]
  token = "token"
  organization = "org"
  bucket_tag = "bucket"
  exclude_bucket_tag = true

This assumes that both buckets are in the same InfluxDBv2 instance…

1 Like

Ok, thanks but unfortunately I haven’t understood that yet.

If I enter the bucket_tag at the output, how does the input know which value it should write in bucket_1 and which it should write in bucket_2?

Can you show me two examples of the UDP send commands for bucket_1 and bucket_2?

@cunnect you wrote

so you sent your data to port 8092 for bucket1 and to port 8093 for bucket2. As you can see in my config, there are two inputs.socket_listener instances, one for each port. The listener for port 8092 then adds a tag bucket = "bucket1" to each metric (through the [inputs.socket_listener.tags] definition). The listener for port 8093 adds bucket = "bucket2" as defined in the config above.

Now every metric received through port 8082 has the bucket tag set to bucket1 and each metric received through port 8083 has the bucket tag set to bucket2. The output will then use the tag with the name defined in the bucket_tag setting (bucket in the case above) to select which bucket a metric should go to based on the value of the tag. So everything received through port 8089 goes to bucket1 and everything received through port 8093 goes to bucket2

Does this make things more clear?

Great and thank you! It works!

1 Like