Get started with InfluxDB tasks

This article walks through writing a basic InfluxDB task that downsamples data and stores it in a new bucket.

Every InfluxDB task needs the following components. Their form and order can vary, but they are all essential parts of a task.

Define task options

Task options define specific information about the task. The example below illustrates how task options are defined in your Flux script:

See for detailed information about each option.

  1. Use from() to query data from InfluxDB . Use other to retrieve data from other sources.
  2. Use range() to define the time range to return data from.

Use task options in your Flux script

Task options are defined in a option record and can be referenced in your Flux script. In the example above, the time range is defined as -task.every.

task.every is dot notation that references the every property of the task option record. is defined as 1h, therefore -task.every equates to -1h.

Using task options to define values in your Flux script can make reusing your task easier.

Process or transform your data

Tasks automatically process or transform data in some way at regular intervals. Data processing can include operations such as downsampling data, detecting anomalies, sending notifications, and more.

Use offset to account for latent data

Use the offset task option to account for potentially latent data (like data from edge devices). A task that runs at one hour intervals () with an offset of five minutes (offset: 5m) executes 5 minutes after the hour, but queries data from the original one hour interval.

See Common tasks for examples of tasks commonly used with InfluxDB.

In most cases, you’ll want to send and store data after the task has transformed it. The destination could be a separate InfluxDB measurement or bucket.

The example below uses to write the transformed data back to another InfluxDB bucket:

To write data into InfluxDB, to() requires the following columns:

  • _time
  • _measurement
  • _value

You can also write data to other destinations using Flux output functions.

Full example task script

To learn more about InfluxDB tasks and how they work, watch the following video: