I calculate the duration of my service-processes using the SUM-Aggregation. Each step of the executed process will be saved in Elasticsearch under a calling Id.
This is what I monitor:
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**
Filter:
{
"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"}}
}
}
}
This returns the complete duration of the process and also tells me which part of the process was the fastest ans which part was the slowest.
Next I want to calculate the average duration of all finished processes by serviceId. In this case I only care about the total duration for each service, so I can comepare them.
How can I create the average, minimum and maximum from my total_durations?
EDIT: I added some sample Data, I hope you can work with it.
Call1:
{
"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
Call2:
{
"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
Aggregation for All Service-Calls for Service ID #1
This is what I want to calculate:
Max: 1202
Min: 1033
AVG: 1116
See Question&Answers more detail:
os