Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Last active July 26, 2022 17:40
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 pmuellr/901926b30bb57a717fd666c94781ef07 to your computer and use it in GitHub Desktop.
Save pmuellr/901926b30bb57a717fd666c94781ef07 to your computer and use it in GitHub Desktop.
Kibana Dev Tools Console queries for the event log
#-------------------------------------------------------
# get 1000 rule SO's
GET .kibana/_search
{
"size": 1000,
"query": {
"bool": {
"filter": [
{"term": {"type": "alert"}}
]
}
}
}
#-------------------------------------------------------
# get 10 event log docs to see the structure
GET .kibana-event-log-7.14.0/_search
#-------------------------------------------------------
# count of rules by type and executions per type by Kibana server
GET .kibana-event-log-7.14.0/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{"range": {"@timestamp": {"gte": "now-1h"}}},
{"term": {"event.provider": "alerting"}},
{"term": {"event.action": "execute"}}
]
}
},
"aggs": {
"ruleTypes": {
"terms": {"field": "rule.category"},
"aggs": {
"on server": {
"terms": {"field": "kibana.server_uuid"},
"aggs": {
"rules for this ruleType": {
"cardinality": {"field": "rule.id"}
}
}
}
}
}
}
}
#-------------------------------------------------------
# stats on rule duration by rule type
GET .kibana-event-log-7.14.0/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{"range": {"@timestamp": {"gte": "now-1h"}}},
{"term": {"event.provider": "alerting"}},
{"term": {"event.action": "execute"}}
]
}
},
"aggs": {
"ruleTypes": {
"terms": {"field": "rule.category"},
"aggs": {
"duration stats for this ruleType": {
"stats": {"field": "event.duration.millis"}
}
}
}
},
"runtime_mappings": {
"event.duration.millis": {
"type": "double",
"script": {
"source": "emit(doc['event.duration'].value / 1000000)"
}
}
}
}
#-------------------------------------------------------
# most expensive rule execution durations
GET .kibana-event-log-7.14.0/_search?_source=false
{
"size": 100,
"query": {
"bool": {
"filter": [
{"range": {"@timestamp": {"gte": "now-1h"}}},
{"term": {"event.provider": "alerting"}},
{"term": {"event.action": "execute"}}
]
}
},
"sort" : [
{"event.duration.millis" : {"order" : "desc"}}
],
"fields": [
"@timestamp",
"kibana.server_uuid",
"rule.category",
"kibana.namespace",
"rule.id",
"rule.name",
"event.duration.millis"
],
"runtime_mappings": {
"event.duration.millis": {
"type": "double",
"script": {
"source": "emit(doc['event.duration'].value / 1000000)"
}
},
"kibana.namespace": {
"type": "keyword",
"script": {
"source": """
def savedObjects = params._source["kibana"]["saved_objects"];
if (savedObjects != null) {
for (def savedObject : savedObjects) {
emit(savedObject["namespace"])
}
}
"""
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment