content/shared/influxdb-v2/tools/kapacitor.md
Kapacitor is a data processing framework that makes it easy to create alerts, run ETL jobs and detect anomalies. Kapacitor interacts with InfluxDB Cloud and InfluxDB OSS {{< current-version >}} using the InfluxDB 1.x compatibility API, so you can continue using Kapacitor without having to migrate libraries of TICKscripts to InfluxDB tasks.
{{% note %}}
InfluxDB Cloud and InfluxDB OSS {{< current-version >}} do not have subscription APIs and do not support Kapacitor stream tasks, but you can continue to use stream tasks by writing data directly to Kapacitor. For more information, see below. {{% /note %}}
To connect Kapacitor to InfluxDB Cloud or InfluxDB OSS {{< current-version >}}, update the [[influxdb]]
section(s) of your Kapacitor configuration file:
Provide your InfluxDB URL in the [[influxdb]].urls configuration option.
For more information, see InfluxDB Cloud regions
or InfluxDB OSS URLs.
[[influxdb]]
# ...
urls = ["http://localhost:8086"]
InfluxDB Cloud and InfluxDB OSS {{< current-version >}} require authentication.
Provide the following credentials in your [[influxdb]].username and [[influxdb]].password
configuration options:
[[influxdb]]
# ...
username = "influxdb-username"
password = "influxdb-token"
{{% warn %}} Kapacitor is subject to InfluxDB token permission restrictions. To query or write to an InfluxDB bucket, the InfluxDB token must have read and/or write permissions for the target bucket. For information about token permissions, see Create a token. {{% /warn %}}
InfluxDB Cloud and InfluxDB OSS {{< current-version >}} do not have subscriptions APIs.
Set the [[influxdb]].disable-subscriptionsto true to disable InfluxDB subscriptions.
[[influxdb]]
# ...
disable-subscriptions = true
Kapacitor batch tasks use the query endpoint of the 1.x compatibility API
and require no change to use with InfluxDB Cloud and InfluxDB OSS.
For information about writing back to InfluxDB in Kapacitor tasks,
see Write back to InfluxDB below.
InfluxDB Cloud and OSS {{< current-version >}} do not have subscription APIs and do not support Kapacitor stream tasks directly.
To use Kapacitor stream tasks, write data directly to Kapacitor using the Kapacitor write API. We recommend using the Telegraf InfluxDB output plugin to write data to both InfluxDB Cloud or OSS and Kapacitor.
To write data to both InfluxDB and Kapacitor using the InfluxDB output plugin, complete the following steps:
database, retention_policy, username and password to match your DBRP mapping, and set skip_database_creation to true:# Write to Kapacitor
[[outputs.influxdb]]
urls = ["http://localhost:9092"]
database = "example-db"
retention_policy = "example-rp"
# Write to InfluxDB Cloud or OSS
[[outputs.influxdb]]
urls = ["http://localhost:8086"]
database = "example-db"
retention_policy = "example-rp"
username = "influxdb-username"
password = "influxdb-token"
skip_database_creation = true
If using the Kapacitor InfluxDBOut node to write data to InfluxDB {{< current-version >}},
InfluxDB maps the specified database and retention policy to a corresponding bucket.
You can also manually map database/retention policy combinations (DBRPs) to buckets.
For more information, see DBRP mapping{{% show-in "v2" %}}.{{% /show-in %}}
{{% show-in "cloud,cloud-serverless" %}}and Create DBRP mappings.{{% /show-in %}}
The following example TICKscript writes to the my-db/my-rp bucket in
InfluxDB Cloud or InfluxDB OSS {{< current-version >}}.
batch
|query('SELECT errors / total AS error_percent from requests')
// Write the transformed data to InfluxDB
|influxDBOut()
.database('my-db')
.retentionPolicy('my-rp')
.measurement('errors')
.tag('kapacitor', 'true')
.tag('version', '0.2')