# Write data in different buckets using telegraf

**URL:** <https://community.influxdata.com/t/write-data-in-different-buckets-using-telegraf/26677>\
**Category:** Telegraf\
**Tags:** telegraf\
**Created:** [September 22, 2022, 4:03pm UTC](https://community.influxdata.com/t/write-data-in-different-buckets-using-telegraf/26677 "2022-09-22T16:03:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/giu-seppe/32/10943_2.png) [@Giu-seppe](https://community.influxdata.com/u/Giu-seppe)\
**Post date:** [September 22, 2022, 4:03pm UTC](https://community.influxdata.com/t/write-data-in-different-buckets-using-telegraf/26677/1 "2022-09-22T16:03:02Z")

</div>

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](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

```auto
# 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

```

```auto
# 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

```

```auto
# 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

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [September 22, 2022, 4:13pm UTC](https://community.influxdata.com/t/write-data-in-different-buckets-using-telegraf/26677/2 "2022-09-22T16:13:16Z")

</div>

> [@Giu-seppe](#):
>
> –config-directory

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](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#metric-filtering) 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.

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/giu-seppe/32/10943_2.png) [@Giu-seppe](https://community.influxdata.com/u/Giu-seppe)\
**Post date:** [September 23, 2022, 7:50am UTC](https://community.influxdata.com/t/write-data-in-different-buckets-using-telegraf/26677/3 "2022-09-23T07:50:33Z")

</div>

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

```auto
# 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 😃
