Skip to content

Instantly share code, notes, and snippets.

View regel's full-sized avatar

Sebastien Leger regel

View GitHub Profile
@regel
regel / kapacitor.conf
Created December 4, 2018 14:52
kapacitor.conf example with Slack settings
data_dir = "/var/lib/kapacitor"
[[slack]]
enabled = true
default = true
workspace = "your_workspace"
url = "your_url"
channel = "your_channel"
global = false
state-changes-only = false
@regel
regel / slack-template.tick
Created December 4, 2018 15:27
A basic TICK script that reads anomalies and sends notifications to the default Slack channel
var model
var from_measurement
var out_db
var retention_policy
var out_measurement
@regel
regel / slack-example.tick
Last active February 16, 2019 07:54
Using TICKscripts with Loud ML, first example
var model = 'telegraf_metrics_count_value_10s'
var from_measurement = 'loudml'
var out_db = 'telegraf'
var retention_policy = 'autogen'
var out_measurement = 'predicted'
@regel
regel / docker-compose-loudml.sh
Last active February 16, 2019 07:53
Cloning Loud ML repo on Github and using the docker compose file
git clone https://github.com/regel/loudml
cd loudml/docker/compose
vim etc/kapacitor.conf # notifications settings
vim etc/loudml.yml # optional: database settings
@regel
regel / section-1.tick
Last active February 16, 2019 07:53
TICK-1 section 1
// the machine learning model name, as defined in settings
var model = 'telegraf_metrics_count_value_10s'
// the measurement name, used by Loud ML to output predictions; default = loudml
var from_measurement = 'loudml'
// the output database name for output data written by this pipeline
var out_db = 'telegraf'
// the retention policy; let's use the default
var retention_policy = 'autogen'
// the output measurement name for output data written by this pipeline
var out_measurement = 'predicted'
@regel
regel / section-2.tick
Last active February 16, 2019 07:58
TICK-1 section 2
var data = stream
// this from node selects all input data received in the given measurement
|from()
.measurement(from_measurement)
.where(lambda: "model" == model)
// this eval node remembers the model name
|eval(lambda: model)
.as('model')
.keep()
// the next five lines save the data to the target database into a new measurement
@regel
regel / section-3.tick
Created December 5, 2018 18:03
TICK-1 section 3
var pos = data
// the next node counts abnormal data points
|stateCount(lambda: "is_anomaly" == TRUE)
|alert()
// Warn after 1 point
.warn(lambda: "state_count" >= 1)
// Critical after 5 points and abnormal higher than 90 / 100
.crit(lambda: "state_count" >= 5 AND "score" > 90.0)
.message('{{ .Time }}: Hey, unexpected situation detected by model={{ index .Fields "model" }} state=ongoing score={{ index .Fields "score" | printf "%0.3f" }}.')
.slack()
@regel
regel / section-4.tick
Created December 5, 2018 18:04
TICK-1 section 4
var neg = data
|stateCount(lambda: "is_anomaly" == FALSE)
|alert()
.info(lambda: "state_count" == 1)
.message('{{ .Time }}: situation back to normal model={{ index .Fields "model" }} state=finished score={{ index .Fields "score" | printf "%0.3f" }}.')
.slack()
@regel
regel / kapacitor-pagerduty.conf
Last active December 9, 2018 21:08
kapacitor.conf section for PagerDuty integration
data_dir = "/var/lib/kapacitor"
[pagerduty2]
enabled = true
routing-key = ""
url = "https://events.pagerduty.com/v2/enqueue"
global = false
[logging]
# Destination for logs
@regel
regel / pagerduty-ml.tick
Created December 9, 2018 21:16
TICK script section triggering alerts to PagerDuty
var pos = data
|changeDetect('is_anomaly')
|alert()
.warn(lambda: "is_anomaly" == TRUE)
.crit(lambda: "is_anomaly" == TRUE AND "score" > 90.0)
.message('{{if ne .Level "OK" }} Hey, unexpected situation detected score={{ index .Fields "score" | printf "%0.3f" }} {{else}} Back to normal {{end}}')
.pagerDuty2()