Created
December 4, 2017 22:41
-
-
Save msjyosh/b78c292289b589513497e07e9e19afa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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