Write data in different buckets using telegraf

Hi all,

I am using Telegraf and InfluxDB together.
I was wondering is it possible to write different plugin metrics each in their own bucket?

To do this I tried using the --config-directory property. I searched the documentation but found only this https://docs.influxdata.com/telegraf/v1.21/administration/configuration/#configuration-file-locations

This is my implementation:

telegraf/
├─ telegraf.d/
│ ├─ ModbusRTU.conf
│ ├─ InternlMonitor.conf
├─ telegraf.conf

# Telegraf.conf


[global_tags]


[agent]
  interval = "10s"
  round_interval = true

  metric_batch_size = 1000

  metric_buffer_limit = 10000

  collection_jitter = "0s"

  flush_interval = "10s"

  flush_jitter = "0s"

  precision = "0s"

  hostname = ""

  omit_hostname = false

# InternalMonitor.conf
#
###############################################################################
#                            OUTPUT PLUGINS                                   #
###############################################################################




# Configuration for sending metrics to InfluxDB 2.0
[[outputs.influxdb_v2]]
alias = "telegraf-stats-db"

  urls = ["http://127.0.0.1:8086"]
  token = "token"
  organization = "xxx"

  ## Destination bucket to write into.
  bucket = "InternalMonitor"




################################################################################
##                            INPUT PLUGINS                                    #
################################################################################

# Collect statistics about itself
[[inputs.internal]]
alias = "telegraf-monitor"
name = "telegraf-monitor"
  ## If true, collect telegraf memory stats.
  collect_memstats = true
# ModbusRTU.conf
#
###############################################################################
#                            OUTPUT PLUGINS                                   #
###############################################################################




# Configuration for sending metrics to InfluxDB 2.0
[[outputs.influxdb_v2]]
alias = "telegraf-stats-db"

  urls = ["http://127.0.0.1:8086"]
  token = "token"
  organization = "xxx"

  ## Destination bucket to write into.
  bucket = "ModbusRTU"




################################################################################
##                            INPUT PLUGINS                                    #
################################################################################


[[inputs.modbus]]
  alias = "modbus RTU"
  name = "modbus RTU"

  
  timeout = "1s"
  busy_retries = 1
  busy_retries_wait = "100ms"
  
  ## Serial (RS485; RS232)
  controller = "file:///COM1"
  baud_rate = 9600
  data_bits = 8
  parity = "N"
  stop_bits = 2

  transmission_mode = "RTU"
  debug_connection = false

  configuration_type = "request"


  [[inputs.modbus.request]]
    slave_id = 1
    byte_order = "ABCD"
    register = "input"
    fields = [
    { address =200 , name = "Phase to neutral Voltage, THD 1" ,type =  "FLOAT32", measurement = "%",omit = false },
    { address =202 , name = "Phase to phase Voltage, THD 2" ,type =  "FLOAT32", measurement = "%",omit = false },
    { address =204 , name = "Phase to phase Voltage, THD 3" ,type =  "FLOAT32", measurement = "%",omit = false },
    ]

    [inputs.modbus.request.tags]
      location = "zoo"
      deviceName = "fido 1"


The problem is that with this configuration each plugin is write in both buckets.
Is there a way to have each plugin written in different buckets?

I’m sure I don’t quite understand the --config-directory parameter can someone enlighten me or give me the link to a useful document?

OS win 10
Telegraf v1.24(nightly version)
InfluxDB v2.2.0

This parameter only allows you to specify a folder to look for configurations. Internally all the files are read and combined into one big config.

What you are looking for is the namepass/tagpass metric selctor config options which help you route metrics to specific plugins.

You could add namepass = ["<metric name>"] to the output you want to collect those metrics, and only those would go there.

1 Like

Wow! everything is clear now
So to get a sorting I could do it this way

# Configuration for sending metrics to InfluxDB 2.0
[[outputs.influxdb_v2]]
alias = "telegraf-stats-db"

  urls = ["http://127.0.0.1:8086"]
  token = "token"
  organization = "xxx"

  ## Destination bucket to write into.
  bucket = "ModbusRTU"
[outputs.influxdb.tagpass]
    alias = ["modbus RTU"]

In this way, only the measurement with an alias equal to “modbus RTU” will pass
Thanks, @jpowers :smiley:

1 Like