# Alert for derivative on accumulative value

**URL:** https://discuss.elastic.co/t/alert-for-derivative-on-accumulative-value/284352
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [September 16, 2021, 4:12am UTC](https://discuss.elastic.co/t/alert-for-derivative-on-accumulative-value/284352 "2021-09-16T04:12:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![NightSpark](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@NightSpark](https://discuss.elastic.co/u/NightSpark)
#### Post date: [September 16, 2021, 4:12am UTC](https://discuss.elastic.co/t/alert-for-derivative-on-accumulative-value/284352/1 "2021-09-16T04:12:10Z")

</div>

Hi all,

I would like to create an alert if the garbage collection time on a JVM takes longer then 20 seconds over any given minute.

I have created the below query to work out the derivative however I am struggling to work out how to create an alert based on this.

Would appreciate any advice on this.

```auto
GET apm-*metric-*/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "match_all": {}
        },
        {
          "range": {
            "@timestamp": {
              "gte": "now-24h",
              "lt": "now"
            }
          }
        },
        {
          "term": {
             "labels.name": "PS MarkSweep"
          }
        }
      ]
    }
  },  
  "aggs": {
    "hostgroup": {
      "terms": {
         "field": "host.ip",
         "size": 10
      },  
      "aggs": {
        "by_date": {
          "date_histogram": {
            "field": "@timestamp",
            "calendar_interval": "minute"  
          },
          "aggs": {  
            "@timestamp": {
              "max": {
                "field": "@timestamp"
              }
            },                  
            "gctime": {
              "max": {
                "field": "jvm.gc.time"
              }
            },
            "gctime_rate": {
                "derivative": {
                  "buckets_path": "gctime.value"
                }
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 14, 2021, 4:12am UTC](https://discuss.elastic.co/t/alert-for-derivative-on-accumulative-value/284352/2 "2021-10-14T04:12:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
