Installing telegraf as a service and to read the .conf files in a folder?


I’m trying to get telegraf installed on a Windows server as a service which I have done, but I’m trying to get it to point to a ‘conf’ folder where all my .conf files will be but get this:

telegraf.exe --service install --config-directory "C:\Program Files\telegraf\conf"


c:\Program Files\telegraf>telegraf.exe --config-directory 'C:\Program Files\telegraf\conf' --test 2022-03-03T08:57:52Z I! Starting Telegraf 1.21.3 2022-03-03T08:57:52Z I! Using config file: C:\Program Files\Telegraf\telegraf.conf 2022-03-03T08:57:52Z W! Telegraf is not permitted to read 'C:\Program 2022-03-03T08:57:52Z I! Loaded inputs: win_perf_counters (2x) 2022-03-03T08:57:52Z I! Loaded aggregators: 2022-03-03T08:57:52Z I! Loaded processors: 2022-03-03T08:57:52Z I! Loaded outputs: influxdb

Any ideas?

Looking at the log, could the blank in the path be the problem?
Program Files

Shouldn’t the wrap work though using " "

Should. But the error message suggests something else? :thinking:
Just try a directory without spaces.

Did that, but it ignores running any .conf files in the “conf” folder, it only reads the main .conf in “C:\telegraf”

I think I sent you this bug in Slack yesterday and I would point out this bug. It is my understanding that the --config-directory option does not work in Windows without another --config option as well.

Try that and let us know what you find out.

I know what’s wrong… the --config parameter is mandatory, I’m not 100% sure about what happens without it but seems like it uses the one in the default path and ignores the rest of the command.

The workaround is pretty simple, create an empty .conf file and us that to satisfy the parameter
telegraf.exe --service install --config '__Path__\empty.conf' --config-directory 'C:\Program Files\telegraf\conf'

I literally have a folder/file structure that looks like this, and in its root, there is the empty.conf file

│   empty.conf
│       agent.conf
│       input_internal.conf.ignore
│       input_sqlserver.conf.ignore
│       telegraf_output_file.conf
1 Like

Just for clarification, is the space in the Windows path also an additional issue? The error log above in the first post suggests that? However, in the GitHub Issue #10356 not, since the configuration working there uses exactly such a path. :thinking:

In case of spaces in a string value, you must wrap the strings around single or double quotes. this is valid for many commands in windows, especially if there are multiple parameters.

  • single quotes represent a static text that is used as is
  • double quotes allow for variable expansions and sometimes require even escaping some characters (this is generally valid, the nearest example is TOML which is used for the config files)

this is why I always use single quotes… unless variables are used

1 Like