# CPU usage and Memory usage

**URL:** <https://discuss.elastic.co/t/cpu-usage-and-memory-usage/87670>\
**Category:** Elasticsearch\
**Created:** [May 31, 2017, 5:39am UTC](https://discuss.elastic.co/t/cpu-usage-and-memory-usage/87670 "2017-05-31T05:39:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kalyan](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@kalyan](https://discuss.elastic.co/u/kalyan)\
**Post date:** [May 31, 2017, 5:39am UTC](https://discuss.elastic.co/t/cpu-usage-and-memory-usage/87670/1 "2017-05-31T05:39:18Z")

</div>

Hi,

I am currently using elasticsearch-5.4.0 and metricbeat-5.4.0 with Kibana. I created a basic elasticsearch setup on ubuntu 16.04 version. I created a watcher so that when CPU usage hits more than 75% i should get an alert with email. When i executed the watch api, i am getting output as given below.  
{  
"error" : {  
"root\_cause" : [  
{  
"type" : "general\_script\_exception",  
"reason" : "failed to compile script [ScriptException[compile error]; nested: IllegalArgumentException[unexpected token ['{'] was expecting one of [{, ';'}].];]"  
}  
],  
"type" : "general\_script\_exception",  
"reason" : "failed to compile script [ScriptException[compile error]; nested: IllegalArgumentException[unexpected token ['{'] was expecting one of [{, ';'}].];]"  
},  
"status" : 500  
}

Can anyone help me out with the situation.

Thanks!  
Kalyan

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 31, 2017, 5:51am UTC](https://discuss.elastic.co/t/cpu-usage-and-memory-usage/87670/2 "2017-05-31T05:51:06Z")

</div>

Can you post what you are trying to send to ES?

---

<div class="post-metadata">

**Author:** ![kalyan](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@kalyan](https://discuss.elastic.co/u/kalyan)\
**Post date:** [May 31, 2017, 5:53am UTC](https://discuss.elastic.co/t/cpu-usage-and-memory-usage/87670/3 "2017-05-31T05:53:27Z")

</div>

Hi Mark,

I am trying to send the below given api.

curl -XPUT '192.168.1.200:9200/\_watcher/watch/cpu\_usage?pretty' -H 'Content-Type: application/json' -d'  
{  
"trigger": {  
"schedule": {  
"interval": "1m"  
}  
},  
"input": {  
"search": {  
"request": {  
"indices": [  
"metricbeat-\*"  
],  
"types" : [  
"node\_stats"  
],  
"body": {  
"size" : 0,  
"query": {  
"filtered": {  
"filter": {  
"range": {  
"timestamp": {  
"gte": "now-2m",  
"lte": "now"  
}  
}  
}  
}  
},  
"aggs": {  
"minutes": {  
"date\_histogram": {  
"field": "timestamp",  
"interval": "minute"  
},  
"aggs": {  
"nodes": {  
"terms": {  
"field": "source\_node.name",  
"size": 10,  
"order": {  
"cpu": "desc"  
}  
},  
"aggs": {  
"cpu": {  
"avg": {  
"field": "node\_stats.process.cpu.percent"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"throttle\_period": "30m",  
"condition": {  
"script": "if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.cpu && node.cpu.value \>= 75;"  
},  
"actions": {  
"send\_email": {  
"transform": {  
"script": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.findAll { return it.cpu && it.cpu.value \>= 75 };"  
},  
"email": {  
"to": "kalyan.vidyayug@yahoo.com",  
"subject": "Watcher Notification - HIGH CPU USAGE",  
"body": "Nodes with HIGH CPU Usage (above 75%):\n\n{{#ctx.payload.\_value}}"{{key}}" - CPU Usage is at {{cpu.value}}%\n{{/ctx.payload.\_value}}"  
}  
}  
}  
}  
'

Thanks!  
Kalyan

---

<div class="post-metadata">

**Author:** ![kalyan](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@kalyan](https://discuss.elastic.co/u/kalyan)\
**Post date:** [May 31, 2017, 9:24am UTC](https://discuss.elastic.co/t/cpu-usage-and-memory-usage/87670/4 "2017-05-31T09:24:00Z")

</div>

Hi,

Can anyone tell which API i need to execute to create watcher for alerting when CPU usage is more than 75%. I did basic elasticsearch-5.4.0 setup on ubuntu 16.04 and metricbeat and kibana as dashboard. I am using xpack for monitoring purpose.

Thanks  
Kalyan

---

<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:** [June 28, 2017, 9:24am UTC](https://discuss.elastic.co/t/cpu-usage-and-memory-usage/87670/5 "2017-06-28T09:24:25Z")

</div>

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