我使用 SUM-Aggregation 计算我的服务流程的持续时间。执行过程的每一步都将保存在 Elasticsearch 中的调用 ID 下。
这是我监控的:
Duration of Request-Processing for ID #123 (calling service #1)
Duration of Server-Response for ID #123 (calling service #1)
**Complete Duration for ID #123**
Duration of Request-Processing for ID #124 (calling service #1)
Duration of Server-Response for ID #124 (calling service #1)
**Complete duration for ID #124**
筛选:
{
"from" : 0, "size" :0,
"query" : {
"filtered" : {
"query" : { "match_all" : {}},
"filter" : {
"term" : {
"callingId" : "123",
}
}
}
},
"aggs" : {
"total_duration" : { "sum" : { "field" : "duration" } },
"max_duration":{"max": {"field":"duration"}},
"min_duration":{"min":{"field":"duration"}}
}
}
}
这将返回该过程的完整持续时间,并告诉我该过程的哪一部分是最快的以及哪一部分是最慢的。
接下来我想通过 serviceId计算所有已完成进程的平均持续时间。在这种情况下,我只关心每个服务的总持续时间,所以我可以比较它们。
如何从我的 total_durations 创建平均值、最小值和最大值?
编辑:我添加了一些示例数据,希望您可以使用它。
呼叫1:
{
"callerId":"U1",
"operation":"Initialize",
"status":"INITIALIZED",
"duration":1,
"serviceId":"1"
}
{
"callerId":"U1",
"operation":"Calculate",
"status":"STARTED",
"duration":1,
"serviceId":"1"
}
{
"callerId":"U1",
"operation":"Finish",
"status":"FINISHED",
"duration":1200,
"serviceId":"1"
}
sum: 1202
呼叫2:
{
"callerId":"U2",
"operation":"Initialize",
"status":"INITIALIZED",
"duration":2,
"serviceId":"1"
}
{
"callerId":"U2",
"operation":"Calculate",
"status":"STARTED",
"duration":1,
"serviceId":"1"
}
{
"callerId":"U2",
"operation":"Finish",
"status":"FINISHED",
"duration":1030,
"serviceId":"1"
}
sum: 1033
服务 ID #1 的所有服务调用的聚合 这是我要计算的:
Max: 1202
Min: 1033
AVG: 1116