# Watcher for cluster JVM

**URL:** <https://discuss.elastic.co/t/watcher-for-cluster-jvm/206485>\
**Category:** Elasticsearch\
**Created:** [November 4, 2019, 9:43pm UTC](https://discuss.elastic.co/t/watcher-for-cluster-jvm/206485 "2019-11-04T21:43:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pazoozoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pazoozoo/32/57125_2.png) [@Pazoozoo](https://discuss.elastic.co/u/Pazoozoo)\
**Post date:** [November 4, 2019, 9:43pm UTC](https://discuss.elastic.co/t/watcher-for-cluster-jvm/206485/1 "2019-11-04T21:43:05Z")

</div>

Hello  
I'm trying to set up a script watcher but it won't trigger.  
Here's my watcher code

```json
{
  "trigger": {
    "schedule": {
      "interval": "5m"
    }
  },
  "input": {
    "http": {
      "request": {
        "scheme": "https",
        "host": "<cluster URL>",
        "port": 9243,
        "method": "get",
        "path": "/_cluster/stats",
        "params": {},
        "headers": {},
        "auth": {
          "basic": {
            "username": "elastic",
            "password": "<password>"
          }
        }
      }
    }
  },
  "condition": {
    "script" : {
      "source" : "return (ctx.payload.nodes.jvm.mem.heap_used_in_bytes / ctx.payload.nodes.jvm.mem.heap_max_in_bytes) > 0.8"
    }
  },
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "to": [
          "<email>"
        ],
        "subject": "ZW Recording JVM heap size: {{ctx.payload.nodes.jvm.mem.heap_used_in_bytes}} bytes",
        "body": {
          "text": "JVM heap size is {{ctx.payload.nodes.jvm.mem.heap_used_in_bytes}} bytes\nPayload: {{ctx.payload.nodes.jvm.mem}}",
          "html": "JVM heap size is <b>{{ctx.payload.nodes.jvm.mem.heap_used_in_bytes}}</b> bytes<br/>Payload: {{ctx.payload.nodes.jvm.mem}}"
        }
      }
    }
  }
}

```

it triggers with a condition of

```auto
return (ctx.payload.nodes.jvm.mem.heap_used_in_bytes / ctx.payload.nodes.jvm.mem.heap_max_in_bytes) > 0

```

or with

```auto
return (ctx.payload.nodes.jvm.mem.heap_used_in_bytes / ctx.payload.nodes.jvm.mem.heap_max_in_bytes) < 1

```

but does not trigger when I'm trying to test it like this:

```auto
return (ctx.payload.nodes.jvm.mem.heap_used_in_bytes / ctx.payload.nodes.jvm.mem.heap_max_in_bytes) > 0.1

```

---

<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:** [December 2, 2019, 9:43pm UTC](https://discuss.elastic.co/t/watcher-for-cluster-jvm/206485/2 "2019-12-02T21:43:07Z")

</div>

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