Tasks are scheduled Flux queries that allow you to process data with InfluxDB.

Task components

Tasks should have the following components:

  • Options
  • Data source
  • Processing steps
  • Destination

Task Options

You can specify options that tasks will use. This makes it easier to reuse and modify your tasks.

option task = {
    // Task name
    name: "monitor task",

    // Run interval
    every: 5m,

    // Cron job
    cron : "0 * * * * *"

    // Task start delay
    offset: 10m,

    // Maximum number of concurrent tasks
    concurrency: 2,

    // Number of tries before getting failed status
    retry: 5,
}

Task data source

You can use the from() function to specify the data you try to get.

data = from(bucket: "status info")
  // `-task.every` is a task option passed here
  |> range(start: -task.every)
  |> filter(fn: (r) =>
    r._measurement == "temperature" and
    r.host == "dataSource"
  )

Data processing and destination

You can use the to() function to store the results in another bucket.

data
  // Process
  |> aggregateWindow(
      every: 1h,
      fn: sum
  )

  // Store results
  |> to(bucket: "status_log", org: "logger")

You can learn more about data processing in the documentation.

Create a task in the UI

In the UI, you can create tasks by the following ways

  • The Data Explorer screen
  • The Task screen
  • Import (in the Task screen)
  • Create from template (in the Settings screen)
  • Clone a taks (in the Task screen)

Data Explorer

  1. Open the Data Explorer
  2. Select Task
  3. Define the task options.
  4. Select a token.
  5. Click Save as Task

Task UI

  1. Open the Task screen
  2. Select Create Task
  3. Click New Task
  4. Define the task options.
  5. Select a token.
  6. Enter your script
  7. Click Save