# Derivativenode-in-kapacitor-batch

**URL:** <https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250>\
**Category:** Kapacitor\
**Created:** [April 1, 2019, 10:25am UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250 "2019-04-01T10:25:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit\_Kumar\_Singh](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/amit_kumar_singh/32/2827_2.png) [@Amit\_Kumar\_Singh](https://community.influxdata.com/u/Amit_Kumar_Singh)\
**Post date:** [April 1, 2019, 10:25am UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/1 "2019-04-01T10:25:26Z")

</div>

I am using derivative node to calculate bandwidth utilization of network devices, below is the script.

```
// database
var database = 'router'

// measurement from where data is coming
var measurement = 'cisco_router'

// RP from where data is coming
var RP = 'autogen'

// which influx cluster to use
var clus = 'network'

// durations
var period = 7m

var every = 10s

// alerts
var crit = 320

var alertName = 'cisco_router_bandwidth_alert'

var triggerType = 'threshold'

batch
|query(''' SELECT (mean("bandwidth_in") * 8) as "value" FROM "router"."autogen"."cisco_router" where host = '10.1.11.1' and ( interface_name = 'GigabitEthernet0/0/0' or interface_name = 'GigabitEthernet0/0/1') ''')
    .cluster('network')
    .period(7m)
    .every(6m)
    .groupBy(*)
|derivative('value')
    .unit(1s)
    .nonNegative()
    .as('value')
|alert()
    .crit(lambda: "value" > crit)
    .stateChangesOnly()
    .message(' {{.Level}} for {{ index .Tags "device_name" }} on Port {{ index .Tags "name" }} {{ .Time.Local.Format "2006.01.02 - 15:04:05" }} ')
    .details('''

 <pre>
 ------------------------------------------------------------------
 CLIENT NAME : XXXXXXXX
 ENVIRONMENT : Prod
 DEVICE TYPE : Router
 CATEGORY : {{ index .Tags "type" }}
 IP ADDRESS : {{ index .Tags "host" }}
 DATE : {{ .Time.Local.Format "2006.01.02 - 15:04:05" }}
 INTERFACE NAME : {{ index .Tags "name" }}
 VALUE : {{ index .Fields "value" }}
 SEVERITY : {{.Level}}
 ------------------------------------------------------------------
 </pre>
 
''')
    .log('/tmp/chronograf/cisco_router_interface_alert.log')
    .levelTag('level')
    .idTag('id')
    .messageField('message')
    .email()
    .to('XXXXXXX')
|influxDBOut()
    .database('chronograf')
    .retentionPolicy(RP)
    .measurement('alerts')
    .tag('alertName', alertName)

```

But it is not showing anything when i do kapacitor watch and not showing any errors in logs.

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [April 2, 2019, 9:22pm UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/2 "2019-04-02T21:22:25Z")

</div>

Hi Amit ,

there will only be an alert when for the mean(“bandwidth”),  
the (current - previous ) / ( time\_difference / unit) \> 320 …

best regards ,  
Marc

---

<div class="post-metadata">

**Author:** ![Amit\_Kumar\_Singh](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/amit_kumar_singh/32/2827_2.png) [@Amit\_Kumar\_Singh](https://community.influxdata.com/u/Amit_Kumar_Singh)\
**Post date:** [April 2, 2019, 10:06pm UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/3 "2019-04-02T22:06:45Z")

</div>

But the thing is when i run kapactior watch task name it does not show any thing it stuck there blank.

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [April 3, 2019, 5:20am UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/4 "2019-04-03T05:20:26Z")

</div>

Hi Amit ,  
what is the output of

```
  Kapacitor list tasks

 Kapacitor show task your_task
```

---

<div class="post-metadata">

**Author:** ![Amit\_Kumar\_Singh](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/amit_kumar_singh/32/2827_2.png) [@Amit\_Kumar\_Singh](https://community.influxdata.com/u/Amit_Kumar_Singh)\
**Post date:** [April 3, 2019, 6:04am UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/5 "2019-04-03T06:04:13Z")

</div>

below are the output.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/e/ea4e56685ea137bae5cbf8125dd776c707eac91d.png)  
and for show task

```
kapacitor show cisco_router_bandwidth_alert
ID: cisco_router_bandwidth_alert
Error: 
Template: 
Type: batch
Status: enabled
Executing: true
Created: 14 Mar 19 16:22 IST
Modified: 01 Apr 19 12:35 IST
LastEnabled: 01 Apr 19 12:35 IST
Databases Retention Policies: ["router"."autogen"]
TICKscript:
// database
var database = 'router'

// measurement from where data is coming
var measurement = 'cisco_router'

// RP from where data is coming
var RP = 'autogen'

// which influx cluster to use
var clus = 'network'

// durations
var period = 7m

var every = 10s

// alerts
var crit = 320

var alertName = 'cisco_router_bandwidth_alert'

var triggerType = 'threshold'

batch
    |query(''' SELECT (mean("bandwidth_in") * 8) as "value" FROM "router"."autogen"."cisco_router" where host = '10.1.11.1' and ( interface_name = 'GigabitEthernet0/0/0' or interface_name = 'GigabitEthernet0/0/1') ''')
        .cluster('network')
        .period(7m)
        .every(6m)
        .groupBy(*)
    |derivative('value')
        .unit(1s)
        .nonNegative()
        .as('value')
    |alert()
        .crit(lambda: "value" > crit)
        .stateChangesOnly()
        .message(' {{.Level}} for {{ index .Tags "device_name" }} on Port {{ index .Tags "name" }} {{ .Time.Local.Format "2006.01.02 - 15:04:05" }} ')
        .details('''

 <pre>
 ------------------------------------------------------------------
 CLIENT NAME : XXXX
 ENVIRONMENT : Prod
 DEVICE TYPE : Router
 CATEGORY : {{ index .Tags "type" }}
 IP ADDRESS : {{ index .Tags "host" }}
 DATE : {{ .Time.Local.Format "2006.01.02 - 15:04:05" }}
 INTERFACE NAME : {{ index .Tags "name" }}
 VALUE : {{ index .Fields "value" }}
 SEVERITY : {{.Level}}
 ------------------------------------------------------------------
 </pre>
 
''')
        .log('/tmp/chronograf/cisco_router_interface_alert.log')
        .levelTag('level')
        .idTag('id')
        .messageField('message')
        .email()
        .to('XXXXXX')
    |influxDBOut()
        .database('chronograf')
        .retentionPolicy(RP)
        .measurement('alerts')
        .tag('alertName', alertName)

DOT:
digraph cisco_router_bandwidth_alert {
graph [throughput="0.00 batches/s"];

query1 [avg_exec_time_ns="2.686601ms" batches_queried="864" errors="0" points_queried="864" working_cardinality="0"];
query1 -> derivative2 [processed="864"];

derivative2 [avg_exec_time_ns="1.408µs" errors="0" working_cardinality="2"];
derivative2 -> alert3 [processed="864"];

alert3 [alerts_inhibited="0" alerts_triggered="0" avg_exec_time_ns="17.881µs" crits_triggered="0" errors="0" infos_triggered="0" oks_triggered="0" warns_triggered="0" working_cardinality="2"];
alert3 -> influxdb_out4 [processed="0"];

influxdb_out4 [avg_exec_time_ns="0s" errors="0" points_written="0" working_cardinality="0" write_errors="0"];
}
```

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [April 3, 2019, 6:40am UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/6 "2019-04-03T06:40:51Z")

</div>

> [@Amit\_Kumar\_Singh](#):
>
> derivative2 [avg\_exec\_time\_ns=“1.408µs” errors=“0” working\_cardinality=“2”]; derivative2 -\> alert3 [processed=“864”]; alert3 [alerts\_inhibited=“0” alerts\_triggered=“0” avg\_exec\_time\_ns=“17.881µs” crits\_triggered=“0” errors=“0” infos\_triggered=“0” oks\_triggered=“0” warns\_triggered=“0” working\_cardinality=“2”]; alert3 -\> influxdb\_out4 [processed=“0”];

Hi Amit ,  
Seems to work fine …  
The DOT section shows that the derivative node has processes 864 data points  
and none of them triggered an alert ,  
It means the result of the DerivativeNode never passes 320 …

---

<div class="post-metadata">

**Author:** ![Amit\_Kumar\_Singh](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/amit_kumar_singh/32/2827_2.png) [@Amit\_Kumar\_Singh](https://community.influxdata.com/u/Amit_Kumar_Singh)\
**Post date:** [April 3, 2019, 7:06am UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/7 "2019-04-03T07:06:41Z")

</div>

I changed the script to send mail when bandwidth is less than 320 but alert still not getting triggered.

![image](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex023/uploads/influxdata/original/2X/a/a36cb99461dbeb76a94e55ec282b1db92422188f.png)

and it is like this for minutes, every other task gives the log and query every time it runs.

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [April 4, 2019, 1:30pm UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/8 "2019-04-04T13:30:38Z")

</div>

Hi Amit ,

can you try with

|alert()  
.crit(lambda: “value” \> 0)

best regards ,

---

<div class="post-metadata">

**Author:** ![Amit\_Kumar\_Singh](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/amit_kumar_singh/32/2827_2.png) [@Amit\_Kumar\_Singh](https://community.influxdata.com/u/Amit_Kumar_Singh)\
**Post date:** [April 4, 2019, 3:41pm UTC](https://community.influxdata.com/t/derivativenode-in-kapacitor-batch/9250/9 "2019-04-04T15:41:39Z")

</div>

I did nothing changed. I think it is something else , kapacitor is not executing script otherwise it would show in `kapacitor watch taskname`.

what could be the reason for `kapacitor watch taskname` for not showing anything in output.

and thanks for the help.
