Telegraf natively supports running as a Windows Service. Outlined below is are the general steps to set it up.
-
Obtain the telegraf windows distribution
-
Create the directory
C:\Program Files\Telegraf
(if you install in a different location simply specify the--config
parameter with the desired location) -
Place the telegraf.exe and the telegraf.conf config file into
C:\Program Files\Telegraf
-
To install the service into the Windows Service Manager, run the following in PowerShell as an administrator (If necessary, you can wrap any spaces in the file paths in double quotes ""):
> C:\"Program Files"\Telegraf\telegraf.exe --service install
-
Edit the configuration file to meet your needs
-
To check that it works, run:
> C:\"Program Files"\Telegraf\telegraf.exe --config C:\"Program Files"\Telegraf\telegraf.conf --test
-
To start collecting data, run:
> net start telegraf
You can also specify a --config-directory
for the service to use:
- Create a directory for config snippets:
C:\Program Files\Telegraf\telegraf.d
- Include the
--config-directory
option when registering the service:> C:\"Program Files"\Telegraf\telegraf.exe --service install --config C:\"Program Files"\Telegraf\telegraf.conf --config-directory C:\"Program Files"\Telegraf\telegraf.d
Telegraf can manage its own service through the --service flag:
Command | Effect |
---|---|
telegraf.exe --service install |
Install telegraf as a service |
telegraf.exe --service uninstall |
Remove the telegraf service |
telegraf.exe --service start |
Start the telegraf service |
telegraf.exe --service stop |
Stop the telegraf service |
You can install multiple telegraf instances with --service-name flag:
> C:\"Program Files"\Telegraf\telegraf.exe --service install --service-name telegraf-1
> C:\"Program Files"\Telegraf\telegraf.exe --service install --service-name telegraf-2
> C:\"Program Files"\Telegraf\telegraf.exe --service uninstall --service-name telegraf-1
When Telegraf runs as a Windows service, Telegraf logs messages to Windows events log before configuration file with logging settings is loaded.
Check event log for an error reported by telegraf
service in case of Telegraf service reports failure on its start: Event Viewer->Windows Logs->Application
Troubleshooting common error #1067
When installing as service in Windows, always double check to specify full path of the config file, otherwise windows service will fail to start
--config "C:\Program Files\Telegraf\telegraf.conf"