<commit_before>---
title: Configuring Telegraf

menu:
  telegraf_1_13:
    name: Configuring
    weight: 20
    parent: Administration
---

The Telegraf configuration file (`telegraf.conf`) lists all of the available plugins. The current version is available here:
[telegraf.conf](https://github.com/influxdata/telegraf/blob/master/etc/telegraf.conf)

## Generating a Configuration File

A default Telegraf configuration file can be auto-generated by Telegraf:

```
telegraf config > telegraf.conf
```

To generate a configuration file with specific inputs and outputs, you can use the
`--input-filter` and `--output-filter` flags:

```
telegraf --input-filter cpu:mem:net:swap --output-filter influxdb:kafka config
```

## Environment variables

Environment variables can be used anywhere in the configuration file by prepending them with `$`. For strings, the variables must be within quotes (i.e., `"$STR_VAR"`) and for numbers and Booleans they should be unquoted (i.e., `$INT_VAR`, `$BOOL_VAR`)

Environment variables can be set using the Linux `export` command
(i.e., `export password=<PASSWORD>`). Using enviroment variables for sensitive
information is considered a best practice.

## Configuration file locations

The location of the configuration file can be set via the `--config` command
line flag.

When the `--config-directory` command line flag is used, files ending with
`.conf` in the specified directory will also be included in the Telegraf
configuration.

On most systems, the default locations are `/etc/telegraf/telegraf.conf` for
the main configuration file and `/etc/telegraf/telegraf.d` for the directory of
configuration files.

# Global tags

Global tags can be specified in the `[global_tags]` section of the config file
in `key="value"` format. All metrics being gathered on this host will be tagged
with the tags specified here.

## Agent configuration

Telegraf has a few options you can configure under the `[agent]` section of the
config.
<commit_msg>add example from telegraf repo<commit_after>---
title: Configuring Telegraf

menu:
  telegraf_1_13:
    name: Configuring
    weight: 20
    parent: Administration
---

The Telegraf configuration file (`telegraf.conf`) lists all of the available plugins. The current version is available here:
[telegraf.conf](https://github.com/influxdata/telegraf/blob/master/etc/telegraf.conf)

## Generating a Configuration File

A default Telegraf configuration file can be auto-generated by Telegraf:

```
telegraf config > telegraf.conf
```

To generate a configuration file with specific inputs and outputs, you can use the
`--input-filter` and `--output-filter` flags:

```
telegraf --input-filter cpu:mem:net:swap --output-filter influxdb:kafka config
```

## Environment variables

Environment variables can be used anywhere in the configuration file by prepending them with `$`. For strings, the variables must be within quotes (i.e., `"$STR_VAR"`) and for numbers and Booleans they should be unquoted (i.e., `$INT_VAR`, `$BOOL_VAR`)

Environment variables can be set using the Linux `export` command
(i.e., `export password=<PASSWORD>`). Using enviroment variables for sensitive
information is considered a best practice.

### Example: Telegraf environment variables

```
/etc/default/telegraf:

USER="alice"
INFLUX_URL="http://localhost:8086"
INFLUX_SKIP_DATABASE_CREATION="true"
INFLUX_PASSWORD="<PASSWORD>"
/etc/telegraf.conf:

[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:

[global_tags]
  user = "alice"

[[outputs.influxdb]]
  urls = "http://localhost:8086"
  skip_database_creation = true
  password = "<PASSWORD>"

```

## Configuration file locations

The location of the configuration file can be set via the `--config` command
line flag.

When the `--config-directory` command line flag is used, files ending with
`.conf` in the specified directory will also be included in the Telegraf
configuration.

On most systems, the default locations are `/etc/telegraf/telegraf.conf` for
the main configuration file and `/etc/telegraf/telegraf.d` for the directory of
configuration files.

# Global tags

Global tags can be specified in the `[global_tags]` section of the config file
in `key="value"` format. All metrics being gathered on this host will be tagged
with the tags specified here.

## Agent configuration

Telegraf has a few options you can configure under the `[agent]` section of the
config.

{'fraction_non_alphanumeric': 0.09476417135439204, 'fraction_numerical': 0.0038944180008654264, 'mean_word_length': 4.7643391521197005, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7554189', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1326, 'n_words': 540}