Telegraf in background

Hi,I want to run the telegraf in background mode. I have created a conf file and while running the conf file telegraf is keep running in that screen and i am unable to anything. Is there anyway to run telegraf in background. It will come out of the screen only when you press Ctrl + C

so how to run this in background so that other things also can be done

How did you install the telegraf agent?

if it was with apt/dpkg then a service should have been created: telegraf.service

Do either of the following work
sudo systemctl start telegraf.service

sudo service telegraf start

If not, then you will need to make a service unit on the server to run telegraf in the background

Hi philb, I have installed the telegraf using the instructions given in the documentation and started using it.
sudo yum localinstall telegraf-1.14.5-1.x86_64.rpm

Can you please help me how to install and the steps for the service/agent to start. Because I want to make that run in background as it is keeps running in the window.


Hmm, centos?

I’ve not tried with yum, but according the docs onces its installed you should be able to issue one of the following depending on the OS version

sudo service telegraf start

OR if you’re using systemd

sudo systemctl start telegraf.service

That should run in the background as far as I’m awre

Hi philb, thanks for the info. I feel I am doing something wrong.there must be some command to execute of need to place the conf file somewhere.i am trying to run using this command(FF_TEST11.conf in my local directory) :

$ telegraf --config FF_TEST11.conf

Hi @oom, apologies for the delay its been a busy day.

On my Ubuntu server my config is stored in /etc/telegraf/telegraf.conf - It loads that one automatically.

Do you have that file directory?

Honestly, I don’t know if there is a flag or argument to run the command as a background process. Not like docker with the -d argument to run it in detatched mode. I think to do what you want you will need to define it as a service.

If you can see the telefgraf.conf file in /etc/telegraf/ then i think the service would be installed.

So, you can update the telegraf.conf file in that directory with your connection details. If you want to test that particular config you mention, you could drop that in to /etc/telegraf/telegraf.d/ but make sure to remove any information from the config that is NOT related to your plugin. So no connection details, no other plugin definintions (ok so you can define more than one in the file, but if that is already defined in the main config you won’t need to)

Then using one of the commands i mentioned to start the service, telegraf should start up and read the telegraf.conf file and the contents of /telegraf.d from within /etc/telegraf/

If it isn;t installed as a service already (it should be if you’ve installed it with a package manager) then this topic might help, its a few years old now but the theory should be the same.

Other than that, I’m not sure what other option there is unfortunately.

I’m out for the weekend, but will be back around on Monday if you’re still struggling to get this going :slight_smile:

Hi philib,
Thanks for the detailed info and it really worked.
but still I am getting some errors on the output.
I placed the conf file under /etc/telegraf/telegraf.d

i have restarted the telegraf and it started creating the Database and loaded records but it has created some different columns.

My Source File is:

but if I see my output it is all different columns;

Where are these columns came from and is it because i have restarted the telegraf or anything wrong I am doing?

Hi @oom

I think that is coming from the name_override line in your config. You’re applying it to the database so any plugins running will be getting that same name. I’m guessing you have some inputs for cpu, memory, disk and so on in your config file.

I would

  1. move the name_overide line to the same block as the plugin definition itsellf
  2. move that entire block of config into a new file, something.conf
  3. place that in /etc/telegraf/telegraf.d
  4. restart the telegraf agent.

At that point the other inputs should start using their default names (dictated by the input itself)

If you then run show measurements from the influx CLI you should get a few different ones like

cpu, mem, disk, diskio, your measurement and possibly others depending on whats in the main telegraf config

restarting telegraf will apply the changes you made, so yes i think restarting it would have caused it. Its an easy enough mistake to make though, you just had the name_override line in the wrong section.

Unfortunately those fields will still appear, if you want to get the clean output just from your CSV you can either drop the current measurement and telegraf will recreate it, or you can just specify a different name in the name_override section

Let me know if that helps