Skip to content

Commit

Permalink
Add load example directory
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Aug 4, 2017
1 parent c3ecf8a commit 54620eb
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 0 deletions.
138 changes: 138 additions & 0 deletions examples/load/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# File based task/template/handler definition

This proposal introduces directory based task, template, and handler definition.

## Configuration

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

`dir` specifies the directory where the definition files exist.

The specified directory should have three subdirectories `tasks`, `templates`, and `handlers`.

The `tasks` directory will contain will contain task tickscripts.

The `templates` directory will contain both template tickscripts and the associated templated task
definition files (either yaml or json).

The `handlers` directory will contain will contain all topic handler definitions in yaml or json.

## tickscript (files with a `.tick` extension)

Tickscripts can be marked up with commented key-value pairs for predefined attributes.
Those attributes may be any of the following

* `id` - the file name without the tick extension
* `type` - determined by introspection of the task (stream, batch)
* `kind` - task, template. defined using a `set statement`
* `subscriptions` - defined using the `subscribe` keyword followed by a specified subscription

For example
```
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)
```

or

```
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')
```

### Template Vars

Template variables may be added as either json or yaml.

* `id` - filename without the `yaml` or `yml` extension
* `dbrp` - required
* `template` - required
* `vars` - list of template vars

```yaml
dbrp:
- telegraf.autogen
- telegraf.not_autogen
template: base_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" }
}
```

or

```json
{
"dbrp": ["telegraf.autogen"],
"template": "base_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" }
}
}
```

## Handlers

Topic handlers must specify its associtated topic like so

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

the name of the file will be used as the handler id.

6 changes: 6 additions & 0 deletions examples/load/handlers/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
topic: cpu
id: example
kind: slack
match: changed() == TRUE
options:
channel: '#alerts'
6 changes: 6 additions & 0 deletions examples/load/handlers/other.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
topic: cpu
id: other
kind: slack
match: changed() == TRUE
options:
channel: '#alerts'
12 changes: 12 additions & 0 deletions examples/load/tasks/cpu_alert.tick
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dbrp "telegraf"."autogen"
dbrp "telegraf"."autogen_not"

stream
|from()
.measurement('cpu')
.groupBy(*)
|alert()
.warn(lambda: "usage_idle" < 20)
.crit(lambda: "usage_idle" < 10)
// Send alerts to the `cpu` topic
.topic('cpu')
9 changes: 9 additions & 0 deletions examples/load/tasks/post.tick
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dbrp "telegraf"."autogen"

stream
|from()
.measurement('cpu')
|alert()
.crit(lambda: "usage_idle" < 50.0)
//.post('http://localhost:2345')
.post('http://localhost:5555')
12 changes: 12 additions & 0 deletions examples/load/templates/another.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id: another
template-id: implicit_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" }
}
14 changes: 14 additions & 0 deletions examples/load/templates/base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: base
dbrps:
- "telegraf.autogen"
template-id: base_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" }
}
23 changes: 23 additions & 0 deletions examples/load/templates/base_template.tick
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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)
12 changes: 12 additions & 0 deletions examples/load/templates/implicit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id: implicit
template-id: implicit_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" }
}
25 changes: 25 additions & 0 deletions examples/load/templates/implicit_template.tick
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
dbrp "telegaf"."not_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)
15 changes: 15 additions & 0 deletions examples/load/templates/other.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "base",
"dbrps": ["telegraf.autogen"],
"template-id": "base_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" }
}
}

0 comments on commit 54620eb

Please sign in to comment.