Multiple telegraf configs


#1

I am running one base config in /etc/telegraf/telegraf.conf and one customized config in /etc/telegraf/telegraf.d . I want to send data to different influx servers designated to each config.

The result I am seeing is data is being duplicated in both the servers. Please guide how to resolve this.


Multiple telegraf configs (data getting duplicated) [solved]
#2

@errishma Are you running two copies of the telegraf daemon? Is the desired result that data is duplicated?

Hey by the way! :wave:


#3

Hi Jack.
Good to hear from you. How are you?
We have one telegraf daemon and two configs Desired result is that data should not be duplicated.


#4

@errishma To run both of the configs you would need to run 2 telegraf daemons. For zero data duplication the two configurations would need to not contain any of the same plugins and each would write to a separate influxdb instance.

I’m great! Enjoying the nice weather down here!


#5

Thanks Jack. How to create multiple Daemon. Please guide.


#6

You would need to run multiple telegraf processes:

$ telegraf -config config1 > telegraf1.log 2>&1 &
$ telegraf -config config2 > telegraf2.log 2>&1 &

If you need systemd or init.d to keep the process alive and start on boot then you would need to copy the service file and change some naming so that you could run:

$ sudo systemctl start telegraf1
$ sudo systemctl start telegraf2
# OR
$ sudo service telegraf1 start
$ sudo service telegraf2 start

Does that help?

Jack


#7

Thanks Jack. Let me test it.

Do we need to create the service like telegraf1 or telegraf2 when systemctl or service is run ?


#8

Yes you would need to create those service files


#9

Where is the existing service file for telegraf?


#10

I think I got it. Please let me know if the approach is wrong.

I created one service telegraf1.service and changed the file to

[Service]
EnvironmentFile=-/etc/default/telegraf1
User=telegraf
Environment='STDOUT=/var/log/telegraf/telegraf1.log’
Environment='STDERR=/var/log/telegraf/telegraf1.log’
ExecStart=/bin/sh -c “exec /usr/bin/telegraf -config /etc/telegraf/telegraf.d/telegraf.conf -config-directory /etc/telegraf/telegraf.d ${TELEGRAF_OPTS} >>${STDOUT} 2>>${STDERR}”

and then ran the command
service telegraf1 start

I see the data going to telegraf1 database in expected server and not duplicated. I will test more on this and let you know if any further issues.

Thank you Jack.
~


#11

Glad you got it working!


#12

@errishma, @jackzampolin can you report exactly how you configure the double telegraf service?

I’m on a centos server and I see all my services at /etc/init.d, telegraf included.
You report instead the content of the telegraf.service file that i locate at /usr/lib/telegraf/scripts/telegraf.service.

I’m a bit confused. What i would do is to copy and rename telegraf service under init.d directory and then modify config path to the second telegraf config file.

How telegraf.service file should be used instead?

thanks,
Ruggiero


#13

It is almost never need required to run multiple Telegraf’s on a single system, including in the original use case of this thread. The proper way to set this up is to use metric filtering to split the output data. Here is an example of splitting the data based on measurement name.


#14

Thank you for the reply daniel. we’ve applicated the tagpass filtering. however imo this solution would be the best suit to address this requirement.

ruggiero