Multiple telegraf configs (data getting duplicated) [solved]

Hello,

I checked the other related post on this Multiple telegraf configs but have an issue

  1. Have 2 telegraf configs under /etc/telegraf/telegraf.d – both are writing to 2 separate InfluxDB databases
  2. Standalone test in the foreground works fine. The below produces separate line protocol outputs (Perfect output)

telegraf --config /etc/telegraf/telegraf.d/telegraf.conf --config-directory /etc/telegraf/telegraf.d --test
telegraf --config /etc/telegraf/telegraf.d/network_telegraf.conf --config-directory /etc/telegraf/telegraf.d --test

  1. Created services in Ubuntu

Service One config

Description=The plugin-driven server agent for reporting metrics into InfluxDB
Documentation=GitHub - influxdata/telegraf: The plugin-driven server agent for collecting & reporting metrics.
After=network.target

[Service]
EnvironmentFile=-/etc/default/telegraf
User=telegraf
ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.d/telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartForceExitStatus=SIGPIPE
KillMode=control-group

[Install]
WantedBy=multi-user.target

Service Two config

[Unit]
Description=The plugin-driven server agent for reporting metrics into InfluxDB
Documentation=GitHub - influxdata/telegraf: The plugin-driven server agent for collecting & reporting metrics.
After=network.target

[Service]
EnvironmentFile=-/etc/default/telegrafnetwork
User=telegraf
ExecStart=/usr/bin/telegraf -config /etc/telegraf/network_telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartForceExitStatus=SIGPIPE
KillMode=control-group

[Install]
WantedBy=multi-user.target

When I start Service-A, I can see data into both InfluxDB databases (duplicated)! Appreciate any assistance.
Start command: sudo systemctl start telegraf.service

Thanks, Kind regards

Try putting your main config outside of the config directory: /etc/telegraf/telegraf.conf and /etc/telegraf/network_telegraf.conf. All files in the config directory are loaded, so I think they are loading each others config.

1 Like

Thanks Daniel will try this. Quick question pls so there shouldn’t be any files/ config files inside config directory (init.d) then ?

Kind regards

The config directory, /etc/telegraf/telegraf.d, is used if you want to split your configuration into multiple files. Any files in this directory are loaded by Telegraf and used to build the full configuration file.

Usually you will keep the main config file outside of this directory and if you are running two Telegraf instances on one machine you will probably want this directory empty or you will want to use a different config-directory for each Telegraf instance.

2 Likes

Perfect, thanks Daniel! Works clean as you neatly explained

  1. Moved multiple configs out of the config directory
  2. Stopped and restarted services - there’s no duplication now.

Thanks much!

Hi daniel. What do you want to say exactly? I created config files under telegraf.d and then I created a database. The database has all measurements from config files under telegraf.d. I do not want this situation.