To detect if data has stopped arriving you should use a deadman's switch. 
The reason for this is that a `select count ...` for a time range doesn't 
return a 0 but rather an empty response if no data exists.

Try something like this 

// Changed this to 7d since that is want you had in your query
var period = 7d
// Changed this  to 1d since you care about missing data for the past 3d
var every = 1d

batch
|query('select bytes from "asgbackup"."autogen"."drive_info" ')
  .period(period)
  .every(every)
// Setup a deadman to trigger an alert if the number of points received is 
<80 over the last 1d.
|deadman(80.0, every)
   // Are target and bytes fields or tags? You say they are fields in your 
description. If they are tag you need to group by them, in order to use 
them here.
  .id('{{ index .Tags "target" }},{{ index .Tags "bytes" }}')
  .message('{{ .ID }} is {{ .Level}} value: {{ index .Fields "emitted" }} 
Values is zero')
  .slack()
  .log('/var/tmp/kapacitor/points.log')

On Thursday, October 27, 2016 at 12:27:49 AM UTC-6, Praveen Gunasekar wrote:
>
> Hi Team,
>
> I am new to write the .tick scripts and stuck at certain point. 
>
> Create a influxdb database with 4 fields. 
> Files, Bytes, Duration, Target and by default time. Everyday there is 
> backup happening and this data will be filed everyday. 
>
> Scenario1: Need tick script. If there is no data for the past 3 days it 
> should trigger an alert in slack. Have write the basic script and seems its 
> not working. 
>
> var period = 2s
> var every = 2s
> var errors = batch
>
> |query('select count(bytes) from "asgbackup"."autogen"."drive_info" where 
> time > now() - 7d')
>   .period(period)
>   .every(every)
> |eval(lambda: "errors.count" < 80)
>   .as ('value')
> |alert()
>   .id('{{ index .Tags "target" }},{{ index .Tags "bytes" }}')
>   .message('{{ .ID }} is {{ .Level}} value: {{ index .Fields "fields" }} 
> Values is zero')
>   .slack()
>   .crit(lambda:TRUE)
>   .log('/var/tmp/kapacitor/points.log')
>
> 1. How do I evaluate the count field in the eval(). 
> 2. Crit condition to satisfy that field. 
> 3. from the influxdb how to print the "time" field. 
>
> Please suggest a solution and correct me in writing a tick scripts. 
>
> - Regards
> Praveen Kumar G
>
>

-- 
Remember to include the version number!
--- 
You received this message because you are subscribed to the Google Groups 
"InfluxData" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
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/0ee081c7-b8fb-4e6e-94aa-8ec0225d9016%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to