Elasticsearch 提供的一个近似度量是 percentiles 百分位数度量。
percentiles 度量告诉我们落在某个百分比以下的所有文档的最小值。例如,如果 50 百分位是 119ms,那么有 50% 的文档数值都不超过 119ms。 percentile_ranks 告诉我们某个具体值属于哪个百分位。119ms 的 percentile_ranks 是在 50 百分位。 这基本是个双向关系。
最近15分钟,99.9的请求的执行时间不超过多少
{
"size": 0,
"query": {
"filtered": {
"filter": {
"range": {
"@timestamp": {
"gt": "now-15m",
"lt": "now"
}
}
}
}
},
"aggs": {
"execute_time": {
"percentiles": {
"field": "upstream_time_ms",
"percents": [
90,
95,
99.9
]
}
}
}
}
//返回值,0.1%的请求超过了159ms
{
"took": 620,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 679400,
"max_score": 0,
"hits": []
},
"aggregations": {
"execute_time": {
"values": {
"90.0": 24.727003484320534,
"95.0": 72.6200981699678,
"99.9": 159.01065773524886 //99.9的数据落在159以内,是系统计算出来159
}
}
}
}
percentile_ranks 指定一个范围,有多少数据落在这里
{
"size": 0,
"query": {
"filtered": {
"filter": {
"range": {
"@timestamp": {
"gt": "now-15m",
"lt": "now"
}
}
}
}
},
"aggs": {
"execute_time": {
"percentile_ranks": {
"field": "upstream_time_ms",
"values": [
50,
160
]
}
}
}
}
//返回值
{
"took": 666,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 681014,
"max_score": 0,
"hits": []
},
"aggregations": {
"execute_time": {
"values": {
"50.0": 94.14716385885366,
"160.0": 99.91130872493076 //99.9的数据落在了160以内,这次,160是我指定的,系统计算出99.9
}
}
}
}