Created
June 19, 2022 10:25
-
-
Save richcollier/13c8659e2102c2bbff7f3820c300c8a1 to your computer and use it in GitHub Desktop.
Watch with simple terms agg and threshold
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
POST _watcher/watch/_execute | |
{ | |
"watch": { | |
"trigger": { | |
"schedule": { | |
"interval": "5m" | |
} | |
}, | |
"input": { | |
"search": { | |
"request": { | |
"indices": [ | |
"farequote" | |
], | |
"body": { | |
"size": 0, | |
"query": { | |
"bool": { | |
"filter": [ | |
{ | |
"range": { | |
"@timestamp": { | |
"gte": "now-5y" | |
} | |
} | |
} | |
] | |
} | |
}, | |
"aggs": { | |
"airlines": { | |
"terms": { | |
"field": "airline", | |
"size": 20 | |
}, | |
"aggs": { | |
"max_responsetime": { | |
"max": { | |
"field": "responsetime" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"condition": { | |
"script": """ | |
return ctx.payload.aggregations.airlines.buckets.stream() | |
.filter(airlines -> airlines.max_responsetime.value > 3000) | |
.count() > 0 | |
""" | |
}, | |
"actions": { | |
"log": { | |
"transform": { | |
"script": """ | |
return ctx.payload.aggregations.airlines.buckets.stream() | |
.filter(airlines -> airlines.max_responsetime.value > 3000) | |
.collect(Collectors.toList()); | |
""" | |
}, | |
"logging": { | |
"text": """ | |
{{#ctx.payload._value}} | |
airline={{key}} exceeded 3sec threshold with responsetime={{max_responsetime.value}} | |
{{/ctx.payload._value}} | |
""" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment