Documentation

Load directory service

The load directory service enables file-based definitions of Kapacitor tasks, templates, and topic handlers that are loaded on startup or when a SIGHUP signal is sent to the process.

Configuration

The load directory service configuration is specified in the [load] section of the Kapacitor configuration file.

[load]
 enabled = true
 dir="/path/to/directory"

dir specifies the directory where the definition files are located.

The service will attempt to load the definitions from three subdirectories.

The tasks directory should contain task TICKscripts and the associated templated task definition files (either YAML or JSON).

The templates directory should contain templated TICKscripts.

The handlers directory will contain topic handler definitions in YAML or JSON.

Tasks

Task files must be placed in the tasks subdirectory of the load service directory. Task TICKscripts are specified based on the following scheme:

  • id - the file name without the .tick extension
  • type - determined by introspection of the task (stream or batch)
  • dbrp - defined using the dbrp keyword followed by a specified database and retention policy

In the following example, the TICKscript will create a stream task named my_task for the dbrp telegraf.autogen.

// /path/to/directory/tasks/my_task.tick
dbrp "telegraf"."autogen"

stream
    |from()
        .measurement('cpu')
        .groupBy(*)
    |alert()
        .warn(lambda: "usage_idle" < 20)
        .crit(lambda: "usage_idle" < 10)
        // Send alerts to the `cpu` topic
        .topic('cpu')

Task templates

Template files must be placed in the templates subdirectory of the load service directory. Task templates are defined according to the following scheme:

  • id - the file name without the tick extension
  • type - determined by introspection of the task (stream or batch)
  • dbrp - defined using the dbrp keyword followed by a specified database and retention policy

The following TICKscript example will create a stream template named my_template for the dbrp telegaf.autogen.

// /path/to/directory/templates/my_template.tick
dbrp "telegraf"."autogen"

var measurement string
var where_filter = lambda: TRUE
var groups = [*]
var field string
var warn lambda
var crit lambda
var window = 5m
var slack_channel = '#alerts'

stream
    |from()
        .measurement(measurement)
        .where(where_filter)
        .groupBy(groups)
    |window()
        .period(window)
        .every(window)
    |mean(field)
    |alert()
         .warn(warn)
         .crit(crit)
         .slack()
         .channel(slack_channel)

Templated tasks

Templated task files must be placed in the tasks subdirectory of the load service directory. Templated tasks are defined according to the following scheme:

  • id - filename without the yaml, yml, or json extension
  • dbrps - required if not specified in template
  • template-id - required
  • vars - list of template vars

In this example, the templated task YAML file creates a stream task, named my_templated_task, for the dbrp telegraf.autogen.

# /path/to/directory/tasks/my_templated_task.tick
dbrps:
  - { db: "telegraf", rp: "autogen"}
template-id: my_template
vars:
  measurement:
   type: string
   value: cpu
  where_filter:
   type: lambda
   value: "\"cpu\" == 'cpu-total'"
  groups:
   type: list
   value:
       - type: string
         value: host
       - type: string
         value: dc
  field:
   type: string
   value : usage_idle
  warn:
   type: lambda
   value: "\"mean\" < 30.0"
  crit:
   type: lambda
   value: "\"mean\" < 10.0"
  window:
   type: duration
   value : 1m
  slack_channel:
   type: string
   value: "#alerts_testing"

The same task can also be created using JSON, as in this example:

{
  "dbrps": [{"db": "telegraf", "rp": "autogen"}],
  "template-id": "my_template",
  "vars": {
    "measurement": {"type" : "string", "value" : "cpu" },
    "where_filter": {"type": "lambda", "value": "\"cpu\" == 'cpu-total'"},
    "groups": {"type": "list", "value": [{"type":"string", "value":"host"},{"type":"string", "value":"dc"}]},
    "field": {"type" : "string", "value" : "usage_idle" },
    "warn": {"type" : "lambda", "value" : "\"mean\" < 30.0" },
    "crit": {"type" : "lambda", "value" : "\"mean\" < 10.0" },
    "window": {"type" : "duration", "value" : "1m" },
    "slack_channel": {"type" : "string", "value" : "#alerts_testing" }
  }
}

Topic handlers

Topic handler files must be placed in the handlers subdirectory of the load service directory.

id: handler-id
topic: cpu
kind: slack
match: changed() == TRUE
options:
  channel: '#alerts'

Was this page helpful?

Thank you for your feedback!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following: