Improve config file environment variable documentation (#5200)

This commit is contained in:
Daniel Nelson 2018-12-27 13:12:00 -08:00 committed by GitHub
parent 219fad60a6
commit 2ff3683b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 2 deletions

View File

@ -24,12 +24,48 @@ telegraf --input-filter cpu:mem:net:swap --output-filter influxdb:kafka config
### Environment Variables ### Environment Variables
Environment variables can be used anywhere in the config file, simply prepend Environment variables can be used anywhere in the config file, simply prepend
them with $. For strings the variable must be within quotes (ie, "$STR_VAR"), them with `$`. Replacement occurs before file parsing. For strings
for numbers and booleans they should be plain (ie, $INT_VAR, $BOOL_VAR) the variable must be within quotes, e.g., `"$STR_VAR"`, for numbers and booleans
they should be unquoted, e.g., `$INT_VAR`, `$BOOL_VAR`.
When using the `.deb` or `.rpm` packages, you can define environment variables When using the `.deb` or `.rpm` packages, you can define environment variables
in the `/etc/default/telegraf` file. in the `/etc/default/telegraf` file.
**Example**:
`/etc/default/telegraf`:
```
USER="alice"
INFLUX_URL="http://localhost:8086"
INFLUX_SKIP_DATABASE_CREATION="true"
INFLUX_PASSWORD="monkey123"
```
`/etc/telegraf.conf`:
```toml
[global_tags]
user = "$USER"
[[inputs.mem]]
[[outputs.influxdb]]
urls = ["$INFLUX_URL"]
skip_database_creation = $INFLUX_SKIP_DATABASE_CREATION
password = "$INFLUX_PASSWORD"
```
The above files will produce the following effective configuration file to be
parsed:
```toml
[global_tags]
user = "alice"
[[outputs.influxdb]]
urls = "http://localhost:8086"
skip_database_creation = true
password = "monkey123"
```
### Configuration file locations ### Configuration file locations
The location of the configuration file can be set via the `--config` command The location of the configuration file can be set via the `--config` command