2016-04-02 10:28:44 +00:00
# Running Telegraf as a Windows Service
2016-07-15 21:00:16 +00:00
Telegraf natively supports running as a Windows Service. Outlined below is are
the general steps to set it up.
1. Obtain the telegraf windows distribution
2. Create the directory `C:\Program Files\Telegraf` (if you install in a different
2018-04-04 23:29:42 +00:00
location simply specify the `--config` parameter with the desired location)
2016-08-29 16:36:05 +00:00
3. Place the telegraf.exe and the telegraf.conf config file into `C:\Program Files\Telegraf`
4. 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 ""):
2016-08-08 14:55:16 +00:00
```
2016-08-29 16:36:05 +00:00
> C:\"Program Files"\Telegraf\telegraf.exe --service install
2016-07-15 21:00:16 +00:00
```
2016-08-08 14:55:16 +00:00
2016-07-15 21:00:16 +00:00
5. Edit the configuration file to meet your needs
6. To check that it works, run:
2016-08-08 14:55:16 +00:00
2016-07-15 21:00:16 +00:00
```
2016-08-29 16:36:05 +00:00
> C:\"Program Files"\Telegraf\telegraf.exe --config C:\"Program Files"\Telegraf\telegraf.conf --test
2016-08-08 14:55:16 +00:00
```
2016-07-15 21:00:16 +00:00
7. To start collecting data, run:
2016-08-08 14:55:16 +00:00
```
> net start telegraf
2016-07-15 21:00:16 +00:00
```
2018-04-04 23:29:42 +00:00
## Config Directory
You can also specify a `--config-directory` for the service to use:
1. Create a directory for config snippets: `C:\Program Files\Telegraf\telegraf.d`
2. 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
```
2016-07-15 21:00:16 +00:00
## Other supported operations
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 |
2016-04-02 10:28:44 +00:00
2018-09-28 01:41:24 +00:00
## Install multiple services
2019-12-10 21:13:03 +00:00
Running multiple instances of Telegraf is seldom needed, as you can run
multiple instances of each plugin and route metric flow using the metric
filtering options. However, if you do need to run multiple telegraf instances
on a single system, you can install the service with the `--service-name` and
`--service-display-name` flags to give the services unique names:
2018-09-28 01:41:24 +00:00
```
2019-12-10 21:13:03 +00:00
> C:\"Program Files"\Telegraf\telegraf.exe --service install --service-name telegraf-1 --service-display-name "Telegraf 1"
> C:\"Program Files"\Telegraf\telegraf.exe --service install --service-name telegraf-2 --service-display-name "Telegraf 2"
2018-09-28 01:41:24 +00:00
```
2019-08-28 21:34:44 +00:00
## Troubleshooting
When Telegraf runs as a Windows service, Telegraf logs messages to Windows events log before configuration file with logging settings is loaded.
2019-12-10 21:13:03 +00:00
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
2019-08-28 21:34:44 +00:00
**Troubleshooting common error #1067 **
2017-07-31 17:58:12 +00:00
When installing as service in Windows, always double check to specify full path of the config file, otherwise windows service will fail to start
2019-08-28 21:34:44 +00:00
--config "C:\Program Files\Telegraf\telegraf.conf"