Skip to content

Instantly share code, notes, and snippets.

@regel
Last active February 16, 2019 07:54
Show Gist options
  • Save regel/221166d99f105a2f83ca2691ab9c1631 to your computer and use it in GitHub Desktop.
Save regel/221166d99f105a2f83ca2691ab9c1631 to your computer and use it in GitHub Desktop.
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'
var data = stream
|from()
.measurement(from_measurement)
.where(lambda: "model" == model)
|eval(lambda: model)
.as('model')
.keep()
var saved = data
|influxDBOut()
.database(out_db)
.retentionPolicy(retention_policy)
.measurement(out_measurement)
var pos = data
|stateCount(lambda: "is_anomaly" == TRUE)
|alert()
// Warn after 1 point
.warn(lambda: "state_count" >= 1)
// Critical after 5 points
.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()
|influxDBOut()
.database(out_db)
.retentionPolicy(retention_policy)
.measurement('pos')
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()
|influxDBOut()
.database(out_db)
.retentionPolicy(retention_policy)
.measurement('neg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment