Skip to content

How to route different metrics in Telegraf to different Influx databases

Written: 2020-01-04







So, at the beginning of the last couple of years I have dropped my Influx Telegraf database containing all the host metrics gathered from the previous year. I did this because it was getting too big, and my container appdata backups where getting too big and taking too long to backup. Yes I know I could have just set a retention policy on the database and have it cleared every week, but I wanted some long term metrics like disk usage, so I could see the growth over the year.

My Influxdb container appdata folder is currently 40GB so lets fix that.

Creating the long term database

Log into your Influxdb instance. If you use docker you can exec in like so: docker exec -it Influxdb influx where Influxdb is the name of the container.

Create the database with the following command: CREATE DATABASE longterm_metrics This creates the database longterm_metrics without any retention policy. If you want a retention policy on the long term metrics, say for example 1 year, you can run this:


This will create the database and set the 365d retention policy to default for that database. If you want you can read more about replication and shards here: and

You can also look up retention policies with the show retention policies command. First select which database to use with the use <database> command and then run the show retention policies command like so:

> use longterm_metrics
Using database longterm_metrics
> show retention policies
name             duration  shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
RP_longterm_365d 8760h0m0s 168h0m0s           1        true

Adding a new default retention policy on the Telegraf database

Run the following command to create a new default retention policy on the telegraf database:


This will ''reset'' the whole database!

The data won't be gone, it's still accessible using the autogen retention policy. But the command below sets the new one as default, and that's what the panels normally use in Grafana.

If you want to migrate some data after you can check out this post


This will create the retention policy called 7_day_retention and set it as the default policy.

After I set the new default retention policy my Influxdb appdata folder went from 40GB to 225MB :)

Read more here:

Sending the metrics to a different database

Now in Telegraf we simply need to add an extra output that tells Telegraf to also route the metrics we want to another database.


This won't stop telegraf from writing the metrics to the OG telegraf database, it will write to both

Add the following to the telegraf.conf file. Note add, not replace.

  urls = [""] # required
  database = "longterm_metrics" # required
  retention_policy = ""
  write_consistency = "any"
  timeout = "5s"
  namepass = ["apcupsd","disk","diskio"]

As I didn't add a retention policy for my long term database I have set it to use an empty string as that will use the default retention policy (autogen) of that database. If you first created the database, and then added a retention policy to that database that you want to use, you must set retention_policy = "<retention_policy>" to the retention policy you want. If not it will use the autogen retention policy as that is set to default when just running create <database>

The namepass = ["apcupsd","disk","diskio"] is what tells Telegraf which metrics to send to that specific database.

After you've added the lines restart Telegraf.

Adding a new datasource in Grafana

Since my Telegraf datasource uses the telegraf database, we need to add a new data source that uses our new database.

Click on Add data source and select InfluxDB.

Next give the data source a name, add the URL to InfluxDB, set the database to use the new database you created and click Save & Test

Updating the Grafana panels

Next it's just a matter of updating the Grafana panels to use the new data source.

If you use my Unraid System Dashboard you can just download the latest version and select the disk data source in the drop down.


If you need any extra help join the Discord server!

Last update: December 18, 2021