我有一个Elasticsearch查询来跟踪来自Elasticsearch Logstash索引的50倍命中率的百分比。
我想在Grafana中实现此功能,但找不到任何好的文档或如何通过UI配置此查询的示例。该用户界面显然支持bucket_script
,但尚不清楚如何实现。
ES查询为:
{
"aggs" : {
"all_hits" : {
"date_histogram" : {
"field" : "@timestamp",
"interval": "day"
},
"aggs": {
"total_hits": {
"value_count": {
"field": "http_status_code"
}
},
"50x": {
"filter": {
"terms": {
"http_status_code": [500,501,502,503,504]
}
},
"aggs": {
"hits": {
"value_count": {
"field": "http_status_code"
}
}
}
},
"error_rate": {
"bucket_script": {
"buckets_path": {
"total_hits": "total_hits",
"error_hits": "50x>hits"
},
"script": "params.error_hits / params.total_hits * 100"
}
}
}
}
}
}