I want to create an alert in Kibana using an Elastic query. I'm using the opendistro alerting feature. I want to check all of the values of the cpu.pct field in the last 10 minutes is greater than 50 and raise an alert if yes.
{
"size": 500,
"query": {
"bool": {
"filter": [
{
"match_all": {
"boost": 1
}
},
{
"match_phrase": {
"client.id": {
"query": "42",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
},
{
"range": {
"cpu.pct": {
"from": 10,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"@timestamp": {
"from": "{{period_end}}||-5m",
"to": "{{period_end}}",
"include_lower": true,
"include_upper": true,
"format": "epoch_millis",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"2": {
"terms": {
"field": "client.name.keyword",
"size": 5,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": {
"_key": "desc"
}
},
"aggregations": {
"3": {
"terms": {
"field": "component.name",
"size": 1000,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"1": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"1": {
"avg": {
"field": "cpu.pct"
}
}
}
}
}
}
}
I have the following query which calculates the average but that's incorrect.
Negative Case : Values (100, 100, 100, 100, 100, 100, 0, 0, 0, 0) | Alert Raised : No (Avg : 60)
Positive Case : Values (60, 60, 60, 60, 60, 60, 60, 60, 60, 60) | Alert Raised : Yes (Avg : 60)
How can I can check against all values?