# How can I use different Influx Database for various telegraf.conf files?

**URL:** https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094
**Category:** Telegraf
**Tags:** telegraf
**Created:** [October 15, 2021, 2:44pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094 "2021-10-15T14:44:14Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 15, 2021, 2:44pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/1 "2021-10-15T14:44:14Z")

</div>

Hello,

I have my main telegraf.conf file in /etc/telegraf/ which contains the Influx database name and password and all my telegraf configuration files (about 30) are in /etc/telegraf/telegraf.d.

They just run SNMP queries again remote devices and puts the results my single influx database, it’s great and then into Grafana.

Most just start off with this:

```auto
[[inputs.snmp]]
  agents = ["10.1.1.1:161"]
  version = 2
  community = "password123"

  [inputs.snmp.tags]
    locationd = "NY"

  [[inputs.snmp.field]]
    name = "hostname"
    oid = "1.3.6.1.2.1.1.5.0"

  [[inputs.snmp.field]]
    name = "uptime"
    oid = "1.3.6.1.2.1.25.1.1.0"

  [[inputs.snmp.field]]
    name = "cpu1"
    oid = "1.3.6.1.2.1.25.3.3.1.2.1"

```

Now I have created a new influx database and a new telegraf.conf file in /etc/telegraf/telegraf.d. and want to send the data to this new database, but it won’t. Instead this new database gets all the new data from the other telegraf files. So I’m getting the same data in both databases now. It seems the telegraf files I have in /etc/telegraf/telegraf.d/ populate both databases now even though I’ve not told them to.

My new telegraf file that I wanted to do to this new database is configured like this:

```auto
[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]
  database = "newdb"
  skip_database_creation = true
  username = "user123"
  password = "passwoord"

[[inputs.snmp]]
  agents = ["10.2.2.2.2:161"]
  version = 2
  community = "password"
  [inputs.snmp.tags]
    location = "NY"

  [[inputs.snmp.field]]
    name = "temp"
    oid = "1.3.6.1.4.1.48690.5.3"

```

Very confused here, does that make any sense?

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 15, 2021, 2:54pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/2 "2021-10-15T14:54:58Z")

</div>

It makes perfectly sense. On startup telegraf reads config from all files and ‘merges’ that all together as if it would be 1 big config file.

So yeah, if you configured 2 outputs without anything extra it will send all metrics to both. You might want to look into [metric filtering](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#metric-filtering).

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 15, 2021, 3:35pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/3 "2021-10-15T15:35:20Z")

</div>

Ah I see!

Apparently I need a another telegraf daemon/instance to be installed so I use /etc/telegraf123/ for example?

Now how do I install a second instance of telegraf on the same server. :S

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 15, 2021, 3:49pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/4 "2021-10-15T15:49:07Z")

</div>

No, there is no need for that. See the docs I linked before, you can select which metrics go to which output.

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 15, 2021, 7:17pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/5 "2021-10-15T19:17:35Z")

</div>

Oh I see, I’m guessing you mean [https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#routing-metrics-to-different-outputs-based-on-the-input](https://this?)

I think it drops everyone then you point to your database and choose the metrics to include.

I just can’t work out from my snmp example on how I can do this (all very new to me).

It s great to know they merge as I thought I was going mad!

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 16, 2021, 5:19am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/6 "2021-10-16T05:19:54Z")

</div>

You need to think how you can differentiate the metrics. You could add a tag saying which db you want it to go, or base on the `agent_host` tag.

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 16, 2021, 9:05am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/7 "2021-10-16T09:05:30Z")

</div>

Do you mean like this? [Using A Telegraf Gateway | InfluxData](https://www.influxdata.com/blog/using-a-telegraf-gateway/)

I’ve looked at mine [https://pastebin.com/hDbQwppy](https://pastebin.com/hDbQwppy) and the above link and can’t seem to understand how mine should look like, I’m not sure if you can give me an example to work on to help me on my way, I’d be so thankful.

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 18, 2021, 7:24am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/8 "2021-10-18T07:24:17Z")

</div>

There are indeed 2 options, use metric filtering as in my docs I linked earlier or put the name of the bucket in a tag. Both options require a tag to be set on the input to be able to differentiate. I still don’t know how you want to differentiate both inputs. (Hint based on the config file is not possible as they all get merged at startup)

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 18, 2021, 8:06am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/9 "2021-10-18T08:06:48Z")

</div>

Hey @Hipska thanks for stinking with me on this, as I know know from what you said all the config files all merge at startup so I need to somehow tag this new config to point to another database and struggling to write a config for this.

My of my configs in telegraf.d (main 1 in telegraf) so I created this new config that I wanted to point to a new database, all my configs include:

telegraf-1.conf

```auto
[[inputs.snmp]]
 agents = ["1.1.1.4:161"]
 version = 2
 community = "mypassword"
  [inputs.snmp.tags]
 location = "New York"
 
[[inputs.snmp.field]]
 name = "lightsensor"
 oid = "1.3.6.1.4.1.48690.5.3"

```

telegraf-2.conf

```auto
[[inputs.snmp]]
 agents = ["1.1.2.4:161"]
 version = 2
 community = "mypassword"
  [inputs.snmp.tags]
 location = "Paris"
 
[[inputs.snmp.field]]
 name = "lightsensor"
 oid = "1.3.6.1.4.1.48690.5.3"

```

telegraf-3.conf

```auto
[[inputs.snmp]]
 agents = ["1.1.3.4:161"]
 version = 2
 community = "mypassword"
  [inputs.snmp.tags]
 location = "London"
 
[[inputs.snmp.field]]
 name = "lightsensor"
 oid = "1.3.6.1.4.1.48690.5.3"

```

So in this example config 1 and 2 will use the default telegraf.conf file and merge with it and use the database configure int there. Config 3 is what I want to go into a new database.

On config 3 is it possible to add a tag to it called “custom123” which the other configs don’t have and be used as the differentiation and then send to the new database? Then any new configs I add I can use that tag to send to this new database and not get merged with the other configs and into the default database?

If so how should this config look?

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 18, 2021, 8:26am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/10 "2021-10-18T08:26:55Z")

</div>

Exactly as you already found [here](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#routing-metrics-to-different-outputs-based-on-the-input).

So the `device-3.conf` would look like this:

```plaintext
[[inputs.snmp]]
  alias = "device-3" # useful for debugging (the logs will show errors came from this config)
  agents = ["1.1.3.4:161"]
  version = 2
  community = "mypassword"
  [inputs.snmp.tags]
    location = "London"
    influxdb_database = "custom123" # here you specify if this needs to go to another DB

  [[inputs.snmp.field]]
    name = "lightsensor"
    oid = "1.3.6.1.4.1.48690.5.3"

```

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 21, 2021, 8:26am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/11 "2021-10-21T08:26:32Z")

</div>

Thanks what about the database password?

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 21, 2021, 8:37am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/12 "2021-10-21T08:37:50Z")

</div>

What is the problem with the password?

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 21, 2021, 8:43am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/13 "2021-10-21T08:43:37Z")

</div>

So I was wondering where I put the password for the new database, this is my reconfigured config, how does it look? I’ve set the DB output at the top and tagged it to use this database and not the main default one, am I missing anything?

[[outputs.influxdb]]  
urls = [“[http://192.168.100.123:8086](http://192.168.100.123:8086)”]  
database = “routersdb”  
skip\_database\_creation = true  
username = “routeruser”  
password = “password1234”

[[inputs.snmp]]  
agents = [“1.1.3.4:161”]  
version = 2  
community = “password1”  
[inputs.snmp.tags]  
location = “London”  
influxdb\_database = “routersdb”

[[inputs.snmp.field]]  
name = “lightsensor”  
oid = “1.3.6.1.4.1.48690.5.3”

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 21, 2021, 9:03am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/14 "2021-10-21T09:03:39Z")

</div>

Yeah, you forgot the parts of tagpass and tagdrop as explained [here](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#routing-metrics-to-different-outputs-based-on-the-input).

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 21, 2021, 12:29pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/15 "2021-10-21T12:29:21Z")

</div>

Like this Hipska? As you can see Im trying not to use the current default database called “defaultdatabase” but use “newdatabase” instead. Also where to I tell the config file to use the “newdatabase” password I configured?

[[outputs.influxdb]]  
urls = [“[http://1.2.3.4:8086](http://1.2.3.4:8086)”]  
#database I don’t wnat to use  
database = “defaultdatabase”  
[outputs.influxdb.tagdrop]  
influxdb\_database = [“\*”]

[[outputs.influxdb]]  
urls = [“[http://1.2.3.4:8086](http://1.2.3.4:8086)”]  
#database I want too use  
database = “newdatabase”  
#database I don’t wont to use  
tagexclude = [“defaultdatabase”]  
[outputs.influxdb.tagpass]  
influxdb\_database = [“newdatabase”]

[[inputs.snmp.field]]  
name = “lightsensor”  
oid = “1.3.6.1.4.1.48690.5.3”  
[inputs.disk.tags]  
influxdb\_database = “newdatabase”

---

<div class="post-metadata">

### Author: ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)
#### Post date: [October 28, 2021, 12:18pm UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/16 "2021-10-28T12:18:46Z")

</div>

If it needs a password, you need to put that in the corresponding outputs.influxdb setting.

But, note if they are both on the same server (with same credentials), you could use the `database_tag` setting and have only one output configured…

---

<div class="post-metadata">

### Author: ![G0nz0uk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/g0nz0uk/32/3554_2.png) [@G0nz0uk](https://community.influxdata.com/u/G0nz0uk)
#### Post date: [October 30, 2021, 9:58am UTC](https://community.influxdata.com/t/how-can-i-use-different-influx-database-for-various-telegraf-conf-files/22094/17 "2021-10-30T09:58:27Z")

</div>

They are 2 different databases, the main one and this new one.

I just want this new telegraf file to use this new databases which has a different username and password to access it.
