Closed love2558 closed 6 years ago
when I create and enable alert task,the task should start to work,Not after 5 minutes or longer
@love2558 thanks for writing in! I think I understand what you are saying. You would like an alert to compare to its historical data immediately rather than waiting to fill its window. In your case it fills its window after 5 minutes.
@nathanielc @desa To get immediate historical results, would the alert need to be a batch rather than a stream?
@goller Yes, you need to use batch in order to be able to query the historical data when the task first starts.
@love2558 Ok, I'm going to change the title of this issue to be "Support kapacitor batch queries"
@goller OK,thank you for your answer! so,chronograf UI don't support kapacitor batch queries,I need to edit the TickScript in order to change the queries type, right?
@love2558 for the moment, yes. That'll be the workaround.
@goller OK,thank you!
@love2558 does this not do what you are looking for?
@goller @nathanielc @nhaugo sorry,I don't know how to write the TickScript in batch queries type,I need to compare current data with historical data,It's too hard.could you give me a demo?
@goller @nathanielc @nhaugo I wrote a TickScript, but it seems to be a problem. Can you give me some advice?
var message = 'batch alerting {{.Time}} {{ index .Fields "value" }}'
var current = batch
|query('''
select mean(nummeasurements) from "_internal"."monitor"."database" where time > now() - 1m
''')
.every(1m)
|eval(lambda: "mean")
.as('value')
var past = batch
|query('''
select mean(nummeasurements) from "_internal"."monitor"."database" where time > now() - 1d - 1m and time < now() - 1d
''')
.every(1m)
|eval(lambda: "mean")
.as('value')
var trigger = past
|join(current)
.as('past', 'current')
|eval(lambda: float("current.mean" - "past.mean"))
.keep()
.as('value')
|alert()
.crit(lambda: "value" > 0)
.stateChangesOnly()
.message(message)
.post('http://xxxxx')
I need to compare the current data with yesterday's data for the same time period,Thank you very much!
@love2558 I've made a couple adjustments to the tickscript you have above
var message = 'batch alerting {{.Time}} {{ index .Fields "value" }}'
var current = batch
|query('select mean(nummeasurements) as value from "_internal"."monitor"."database"')
.period(1m)
.every(1m)
.align()
var past = batch
|query('select mean(nummeasurements) as value from "_internal"."monitor"."database"')
.period(1m)
.every(1m)
.align()
.offset(24h)
|shift(24h)
var trigger = past
|join(current)
.as('past', 'current')
|eval(lambda: float("current.value" - "past.value"))
.keep()
.as('value')
|alert()
.crit(lambda: "value" > 0)
.stateChangesOnly()
.message(message)
.post('http://xxxxx')
@desa Thank you very much!
I want to compare the current data with the data from 5 minutes ago. so,I create the alert rules, the rules are as follows:
But the result is not what I want,It can't be compared to the past, and it always starts when the rules are created. For example,The current time is 10:15, and I create the alert rule,It can only compare 10:20 minutes with 10:15 minutes instead of 10:15 and 10:10.the result is not what I want! do you understand what I mean?