-
Nikolay Stanchev authoredNikolay Stanchev authored
relative-stream-template.tick 1.30 KiB
var db string // database per service function chain, so db is named after sfc
var rp = 'autogen' // default value for the retention policy
var measurement string
var selectLambda lambda // must be a lambda specifying the field to select e.g. "requests"
var whereClause = lambda: True // default value is a function which returns TRUE, hence no filtering of the query result
var messageValue = 'TRUE' // default value is TRUE, as this is what SFEMC expects as a notification for an event rule
var comparisonLambda lambda // comparison function e.g. "diff" > 40
var alertPeriod duration
var topicID string
var data = stream
| from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.where(whereClause)
| eval(selectLambda)
.as('value')
var past = data
| shift(alertPeriod)
var current = data
past
| join(current) // NOTE: join buffers a given data point until a point with the correct timestamp to join on arrives
.as('past', 'current')
| eval(lambda: float("current.value" - "past.value"))
.keep()
.as('diff')
| alert()
.id(topicID)
.details('db=' + db + ',measurement=' + measurement)
.crit(comparisonLambda)
.message(messageValue)
.topic(topicID)
.noRecoveries()