Skip to content

Commit 6d0c58a

Browse files
committed
Convert metric threshold rules to ESQL
1 parent 7329451 commit 6d0c58a

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

packages/elastic_agent/kibana/alerting_rule_template/elastic-agent-cpu-usage-spike-rule.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44
"attributes": {
55
"name": "[Elastic Agent] CPU usage spike",
66
"tags": ["Elastic Agent", "Resource Consumption"],
7-
"ruleTypeId": "metrics.alert.threshold",
7+
"ruleTypeId": ".es-query",
88
"schedule": {
99
"interval": "1m"
1010
},
1111
"params": {
12-
"criteria": [
13-
{
14-
"aggType": "max",
15-
"comparator": ">",
16-
"threshold": [0.8],
17-
"timeSize": 5,
18-
"timeUnit": "m",
19-
"metric": "system.process.cpu.total.pct"
20-
}
21-
],
22-
"sourceId": "default",
23-
"alertOnNoData": false,
24-
"alertOnGroupDisappear": false,
25-
"filterQueryText": "process.executable.text : \"*elastic*agent*\"",
26-
"filterQuery": "{\"bool\":{\"should\":[{\"match_phrase\":{\"process.executable.text\":\"*elastic-agent*\"}}],\"minimum_should_match\":1}}",
27-
"groupBy": ["agent.id", "process.name"]
12+
"searchType": "esqlQuery",
13+
"timeWindowSize": 7,
14+
"timeWindowUnit": "m",
15+
"threshold": [0],
16+
"thresholdComparator": ">",
17+
"size": 100,
18+
"esqlQuery": {
19+
"esql": "FROM metrics-*\n | WHERE process.executable LIKE \"*elastic*agent*\"\n | STATS cpu_process_pct = MAX(system.process.cpu.total.pct) * 100\n BY elastic_agent.id, process.name,\n time_bucket = BUCKET(@timestamp, 1 minute)\n // Count the 1 minute timebuckets that are above 80% by process and agent\n | WHERE cpu_process_pct >= 80\n | STATS count_above_threshold = COUNT(*)\n BY elastic_agent.id, process.name\n // Alert if there are 5 or more occurences\n | WHERE count_above_threshold >= 5"
20+
},
21+
"aggType": "count",
22+
"groupBy": "row",
23+
"termSize": 5,
24+
"sourceFields": [],
25+
"timeField": "@timestamp",
26+
"excludeHitsFromPreviousRun": true
2827
},
2928
"alertDelay": {
3029
"active": 1

packages/elastic_agent/kibana/alerting_rule_template/elastic-agent-high-pipeline-queue.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44
"attributes": {
55
"name": "[Elastic Agent] High pipeline queue",
66
"tags": ["Elastic Agent", "Pipeline and Queues"],
7-
"ruleTypeId": "metrics.alert.threshold",
7+
"ruleTypeId": ".es-query",
88
"schedule": {
99
"interval": "1m"
1010
},
1111
"params": {
12-
"criteria": [
13-
{
14-
"aggType": "max",
15-
"comparator": ">",
16-
"threshold": [0.9],
17-
"timeSize": 1,
18-
"timeUnit": "m",
19-
"metric": "beat.stats.libbeat.pipeline.queue.filled.pct"
20-
}
21-
],
22-
"sourceId": "default",
23-
"alertOnNoData": true,
24-
"alertOnGroupDisappear": false,
25-
"groupBy": ["elastic_agent.id", "component.id"]
12+
"searchType": "esqlQuery",
13+
"timeWindowSize": 5,
14+
"timeWindowUnit": "m",
15+
"threshold": [0],
16+
"thresholdComparator": ">",
17+
"size": 100,
18+
"esqlQuery": {
19+
"esql": "TS metrics-*\n| WHERE data_stream.dataset == \"elastic_agent.*beat\"\n| STATS pipeline_queue_pct = MAX(beat.stats.libbeat.pipeline.queue.filled.pct) * 100 BY elastic_agent.id, process.name\n| WHERE pipeline_queue_pct >= 90"
20+
},
21+
"aggType": "count",
22+
"groupBy": "row",
23+
"termSize": 5,
24+
"sourceFields": [],
25+
"timeField": "@timestamp",
26+
"excludeHitsFromPreviousRun": true
2627
},
2728
"alertDelay": {
2829
"active": 1

0 commit comments

Comments
 (0)