Skip to content

Instantly share code, notes, and snippets.

@msjyosh
Created December 4, 2017 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msjyosh/b78c292289b589513497e07e9e19afa3 to your computer and use it in GitHub Desktop.
Save msjyosh/b78c292289b589513497e07e9e19afa3 to your computer and use it in GitHub Desktop.
curl -XPUT 'localhost:9200/_watcher/watch/mem_watch?pretty' -H 'Content-Type: application/json' -d'
{
"trigger": {
"schedule": {
"interval": "1m"
}
},
"input": {
"search": {
"request": {
"indices": [
".marvel-es-1-*"
],
"types": [
"node_stats"
],
"body": {
"size": 0,
"query": {
"bool": {
"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": {
"memory": "desc"
}
},
"aggs": {
"memory": {
"avg": {
"field": "node_stats.jvm.mem.heap_used_percent"
}
}
}
}
}
}
}
}
}
}
},
"throttle_period": "30m",
"condition": {
"script": {
"lang": "groovy",
"inline": "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.memory && node.memory.value >= 75;"
}
},
"actions": {
"send_email": {
"transform": {
"script": {
"lang": "groovy",
"inline": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.findAll { return it.memory && it.memory.value >= 75 };"
}
},
"email": {
"to": "test@test.com",
"subject": "Watcher Notification - HIGH MEMORY USAGE",
"body": "Nodes with HIGH MEMORY Usage (above 75%):{{#ctx.payload._value}} {{key}} - Memory Usage is at {{memory.value}}%{{ctx.payload._value}}"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment