docs-v2/content/v2.0/write-data/use-telegraf/manual-config.md

4.2 KiB

title seotitle description aliases menu weight
Manually configure Telegraf Manually configure Telegraf for InfluxDB v2.0 Update existing or create new Telegraf configurations to use the `influxdb_v2` output plugin to write to InfluxDB v2.0. Start Telegraf using the custom configuration.
/v2.0/collect-data/use-telegraf/manual-config
v2_0
parent
Use Telegraf
202

Use the Telegraf influxdb_v2 output plugin to collect and write metrics into an InfluxDB v2.0 bucket. This article describes how to enable the influxdb_v2 output plugin in new and existing Telegraf configurations, then start Telegraf using the custom configuration file.

{{% note %}} View the requirements for using Telegraf with InfluxDB v2.0. {{% /note %}}

Configure Telegraf input and output plugins

Configure Telegraf input and output plugins in the Telegraf configuration file (typically named telegraf.conf). Input plugins collect metrics. Output plugins define destinations where metrics are sent.

See Telegraf plugins for a complete list of available plugins.

Enable and configure the InfluxDB v2 output plugin

To send data to an InfluxDB v2.0 instance, enable in the influxdb_v2 output plugin in the telegraf.conf.

Specify the following:

urls

An array of URLs for your InfluxDB v2.0 instances. By default, InfluxDB runs on port 9999.

{{% cloud-msg %}}

{{< cloud-name "short" >}} URL

To write data to an {{< cloud-name "short" >}} instance, use the URL of your {{< cloud-name "short" >}} user interface (UI). {{< cloud-name >}} requires HTTPS.

For example: https://us-west-2-1.aws.cloud2.influxdata.com {{% /cloud-msg %}}

token

Your InfluxDB v2.0 authorization token. For information about viewing tokens, see View tokens.

{{% note %}}

Avoid storing tokens in plain text

InfluxData does not recommend storing authentication tokens in plain text in the telegraf.conf. A secure alternative is to set the INFLUX_TOKEN environment variable and include it into your configuration file.

{{< tabs-wrapper >}} {{% tabs %}} macOS or Linux Windows {{% /tabs %}}

{{% tab-content %}}

export INFLUX_TOKEN=YourAuthenticationToken

{{% /tab-content %}}

{{% tab-content %}}

{{< code-tabs-wrapper >}} {{% code-tabs %}} PowerShell CMD {{% /code-tabs %}}

{{% code-tab-content %}}

$env:INFLUX_TOKEN = “YourAuthenticationToken"

{{% /code-tab-content %}}

{{% code-tab-content %}}

set INFLUX_TOKEN=YourAuthenticationToken 
# Make sure to include a space character at the end of this command.

{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}

{{% /tab-content %}} {{< /tabs-wrapper >}}

See the example telegraf.conf below. {{% /note %}}

organization

The name of the organization that owns the target bucket.

bucket

The name of the bucket to write data to.

Example influxdb_v2 configuration

The example below illustrates influxdb_v2 configurations that write to InfluxDB OSS or {{< cloud-name >}}.

{{< code-tabs-wrapper >}} {{% code-tabs %}} InfluxDB OSS {{< cloud-name "short" >}} {{% /code-tabs %}} {{% code-tab-content %}}

# ...

[[outputs.influxdb_v2]]
  urls = ["http://localhost:9999"]
  token = "$INFLUX_TOKEN"
  organization = "example-org"
  bucket = "example-bucket"

# ...

{{% /code-tab-content %}} {{% code-tab-content %}}

# ...

[[outputs.influxdb_v2]]
  urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]
  token = "$INFLUX_TOKEN"
  organization = "example-org"
  bucket = "example-bucket"

# ...

{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}

{{% note %}}

Write to InfluxDB v1.x and v2.0

If a Telegraf agent is already writing to an InfluxDB v1.x database, enabling the InfluxDB v2 output plugin will write data to both v1.x and v2.0 instances. {{% /note %}}

Start Telegraf

Start the Telegraf service using the -config flag to specify the location of your telegraf.conf.

telegraf -config /path/to/custom/telegraf.conf