influxdata / kapacitor

Open source framework for processing, monitoring, and alerting on time series data
MIT License
2.32k stars 493 forks source link

Unable to print the value for a condition #1022

Open gkpraveen1988 opened 8 years ago

gkpraveen1988 commented 8 years ago

Hi All,

Wrote the below tick scripts to print the field "Duration" in the slack channel for the condition of "target". However, the below seems to be not giving any alerts in the slack channel

var period = 2s
var every = 2s
var data = stream

|from()
  .database('asgbackup')
  .retentionPolicy('autogen')
  .measurement('drive_info')
  .where(lambda: "target" =~ 'Mysqltest6')
  .groupBy(*)
|window()
  .period(period)
  .every(every)
|alert()
  .message('Duration: {{ index .Fields "duration" }}')
  .crit(lambda: TRUE)
  .slack()
  .log('/var/tmp/kapacitor/files.log')

Could you please help in what might be wrong..

nathanielc commented 8 years ago

@gkpraveen1988 Does your drive_info measurement have a duration field? Or are you expecting duration to be the duration of the alert?

gkpraveen1988 commented 8 years ago

Hi Nathan, Thanks for your response. Measurement = drive_info Database = asgbackup Retentionpolicy = autogen

target = tag bytes, duration, files = fields

Also, tried some thing of the below. this is not alerting in slack channel.

var last_value = batch |query(''' select target as last_target,bytes from "asgbackup"."autogen"."drive_info" LIMIT 1 ''') .period(30d) .every(5s)

var last_24h_stddev = batch |query(''' SELECT stddev("duration") AS durationstd FROM "asgbackup"."autogen"."drive_info" WHERE target='Mysqltest8' ''') .period(30d) .every(5s) .groupBy('target')

last_value |join(last_24h_stddev) .as('target_val', 'stddev')

|eval(lambda: "target_val.last_target", lambda: "stddev.durationstd")
    .as('tgt_val', 'std_dev')
|alert()
    .message('Last value: {{ index .Fields "tgt_val" }}, Last deviation: {{ index .Fields "std_dev" }}')
    .crit(lambda: TRUE)
    .slack()
    .log('/var/tmp/kapacitor/files.log')

All I need is to print the values of 1st and 2nd query in the slack using a join condition. This is not happening. Please help.

nathanielc commented 8 years ago

Add .align() to your batch queries. This will ensure they have matching times when they go to be joined.