Skip to content

Instantly share code, notes, and snippets.

@regel
Last active February 16, 2019 07:53
Show Gist options
  • Save regel/b544cc76dcde36638bc17afeca00c19d to your computer and use it in GitHub Desktop.
Save regel/b544cc76dcde36638bc17afeca00c19d to your computer and use it in GitHub Desktop.
TICKscript example triggering alerts on PagerDuty
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
|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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment