Try it this way (comments inline explaining the difference): // This is my script var today_trips = batch |query(''' SELECT count(count) as count FROM "product"."default".leads ''') .period(24h) .cron('28 18 * * * *') |log()
var yesterday_trips = batch |query(''' SELECT count(count) as count FROM "product"."default".leads ''') .period(24h) // Use offset to skip the most recent 24h .offset(24h) .cron('28 18 * * * *') // shift times to match with today's times |shift(24h) |log() today_trips |join(yesterday_trips) .as('today_trips', 'yesterday_trips') .fill(0.0) |eval( lambda: int("today_trips.count"), lambda: int("yesterday_trips.count"), lambda: float(100.0 * float(float("today_trips.count" - "yesterday_trips.count") / float("yesterday_trips.count"))) ) .as('today_trip', 'yester_trip', 'perc') |log() |alert() .id('Lead creation Dip/Increase alert Task Name : {{ .TaskName }}') .message('{{ .ID }}, Alert Time : {{.Time}}') .details(''' <h4>{{ .Message }}</h4> <p>Total Trip Created in last 24 hours: {{ index .Fields "today_trip" }}</p> <p>Total Trip Created in last 24 to 48 hours: {{ index .Fields "yester_trip" }}</p> <p>Trip Dip/Increase: {{ index .Fields "perc" | printf "%0.2f" }}% </p> ''') .info(lambda: "perc" < -1.0 OR "perc" > 1.0) .log('/var/log/kapacitor/kapacitor.log') As for how tolerance/rounding works this is the underlying function https://golang.org/pkg/time/#Time.Round. The reason why it didn't join is because of the round up behavior on the half way mark of the round function. See this example of go code illustrating the issue: https://play.golang.org/p/L2xs4-hhb6 But all that said the fix I suggested doesn't require a tolerance since the times on the points will be exactly the same, by using the offset+shift steps. On Thursday, September 15, 2016 at 2:38:35 AM UTC-6, Sourav Kumar wrote: > > // This is my script > var today_trips = batch > |query(''' > SELECT count(count) as count > FROM "product"."default".leads > ''') > .period(24h) > .cron('28 18 * * * *') > |log() > > var yesterday_trips = batch > |query(''' > SELECT count(count) as count > FROM "product"."default".leads > WHERE "time" < now() - 1d > ''') > .period(48h) > .cron('28 18 * * * *') > |log() > > today_trips > |join(yesterday_trips) > .as('today_trips', 'yesterday_trips') > .tolerance(48h) > .fill(0.0) > |eval( > lambda: int("today_trips.count"), > lambda: int("yesterday_trips.count"), > lambda: float(100.0 * float(float("today_trips.count" - > "yesterday_trips.count") / float("yesterday_trips.count"))) > ) > .as('today_trip', 'yester_trip', 'perc') > |log() > |alert() > .id('Lead creation Dip/Increase alert Task Name : {{ .TaskName }}') > .message('{{ .ID }}, Alert Time : {{.Time}}') > .details(''' > <h4>{{ .Message }}</h4> > <p>Total Trip Created in last 24 hours: {{ index .Fields > "today_trip" }}</p> > <p>Total Trip Created in last 24 to 48 hours: {{ index .Fields > "yester_trip" }}</p> > <p>Trip Dip/Increase: {{ index .Fields "perc" | printf "%0.2f" > }}% </p> > ''') > .info(lambda: "perc" < -1.0 OR "perc" > 1.0) > .log('/var/log/kapacitor/kapacitor.log') > > > Log of this Script > Log 1-- when data point joined > [leads:log2] 2016/09/13 17:37:00 I! {leads 2016-09-13 17:37:00 +0000 UTC > false map[] [{2016-09-12 17:37:00 +0000 UTC map[count:2653] map[]}]} > [leads:log4] 2016/09/13 17:37:00 I! {leads 2016-09-13 17:37:00 +0000 UTC > false map[] [{2016-09-11 17:37:00 +0000 UTC map[count:2295] map[]}]} > [leads:log8] 2016/09/13 17:37:00 I! {leads 2016-09-14 00:00:00 +0000 UTC > false map[] [{2016-09-12 00:00:00 +0000 UTC map[perc:15.59912854030501 > today_trip:2653 yester_trip:2295] map[]}]} > > > Log 2 -- when data point not joined > [leads:log2] 2016/09/14 19:22:00 I! {leads 2016-09-14 19:22:00 +0000 UTC > false map[] [{2016-09-13 19:22:00 +0000 UTC map[count:2261] map[]}]} > [leads:log4] 2016/09/14 19:22:00 I! {leads 2016-09-14 19:22:00 +0000 UTC > false map[] [{2016-09-12 19:22:00 +0000 UTC map[count:2666] map[]}]} > [leads:log8] 2016/09/14 19:22:00 I! {leads 2016-09-15 00:00:00 +0000 UTC > false map[] [ > {2016-09-12 00:00:00 +0000 UTC map[today_trip:0 yester_trip:2666 > perc:-100] map[]} {2016-09-15 00:00:00 +0000 UTC map[yester_trip:0 > perc:+Inf today_trip:2261] map[]}]} > > > why this batch query joins some time but same batch query not join > Can you also explain how tolerance round up time stamp > -- Remember to include the InfluxDB version number with all issue reports --- You received this message because you are subscribed to the Google Groups "InfluxDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to influxdb+unsubscr...@googlegroups.com. To post to this group, send email to influxdb@googlegroups.com. Visit this group at https://groups.google.com/group/influxdb. To view this discussion on the web visit https://groups.google.com/d/msgid/influxdb/b3984eaf-74ec-440d-b089-6d2394a96c76%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.