content/telegraf/v1/get-started.md
After you've downloaded and installed Telegraf, you're ready to begin collecting and sending data. To collect and send data, do the following:
Define which plugins Telegraf will use in the configuration file. Each configuration file needs at least one enabled input plugin (where the metrics come from) and at least one enabled output plugin (where the metrics go).
The following example generates a sample configuration file with all available plugins, then uses filter flags to enable specific plugins.
{{% note %}}
For details on filter and other flags, see Telegraf commands and flags.
{{% /note %}}
Run the following command to create a configuration file:
telegraf --sample-config > telegraf.conf
Locate the configuration file. The location varies depending on your system:
/usr/local/etc/telegraf.conf/etc/telegraf/telegraf.confNote: You can also specify a remote URL endpoint to pull a configuration file from. See Configuration file locations.
Edit the configuration file using vim or a text editor. Because this example uses InfluxDB V2 output plugin, we need to add the InfluxDB URL, authentication token, organization, and bucket details to this section of the configuration file.
Note: For more configuration file options, see Configuration options.
cpu and mem) with the --input-filter flag.
Specify InfluxDB as the output with the --output-filter flag.telegraf --sample-config --input-filter cpu:mem --output-filter influxdb_v2 > telegraf.conf
The resulting configuration will collect CPU and memory data and sends it to InfluxDB V2.
For an overview of how to configure a plugin, watch the following video:
{{< youtube a0js7wiQEJ4 >}}
Add environment variables anywhere in the configuration file by prepending them with $.
For strings, variables must be in quotes (for example, "$STR_VAR").
For numbers and Booleans, variables must be unquoted (for example, $INT_VAR, $BOOL_VAR).
You can also set environment variables using the Linux export command: export password=mypassword
Note: We recommend using environment variables for sensitive information.
In the Telegraf environment variables file (/etc/default/telegraf):
USER="alice"
INFLUX_URL="http://localhost:8086"
INFLUX_SKIP_DATABASE_CREATION="true"
INFLUX_PASSWORD="monkey123"
In the Telegraf configuration file (/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 environment variables above add the following configuration settings to Telegraf:
[global_tags]
user = "alice"
[[outputs.influxdb]]
urls = "http://localhost:8086"
skip_database_creation = true
password = "monkey123"
Next, you need to start the Telegraf service and direct it to your configuration file:
telegraf --config telegraf.conf
systemctl start telegraf