22 Aug 2024 06:18 PM - last edited on 26 Aug 2024 07:11 AM by MaciejNeumann
Hello,
I was asked from a client to add to a dash a custom metric for some key requests i have. Specifically i was asked to create this metric:
Weighted Median Response Time = (Key_request_X Median Response Time * Key_request_X Count + Key_request_Y Median Response Time * Key_request_Y Count)/ (Key_request_X Request Count + Key_request_Y Count)
Is there a way to do this and actually show it in a dashboard?
Thank you in advance
23 Aug 2024 07:46 AM
Hi @Dimitris_Pin ,
I think you can get it using these two base queries:
builtin:service.keyRequest.response.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequest~")"))))):median
builtin:service.keyRequest.count.total:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequest~")")))))
and then combine them with mathematic operators:
Ex:
((builtin:service.keyRequest.response.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"getConfiguration~")"))))):median) * (builtin:service.keyRequest.count.total:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"getConfiguration~")")))))) ) + ......
Hope it helps.
Regards,
Elena.
23 Aug 2024 08:06 AM
Hello Dimitris,
You should be able to create a tile using Dataexplorer with the following Advanced mode query:
((
builtin:service.keyRequest.count.client:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"Key_request_X~")"))))):splitBy("dt.entity.service_method"):avg:default(0)
*
builtin:service.keyRequest.response.time:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"Key_request_X~")"))))):splitBy("dt.entity.service_method"):avg:default(0)
+
builtin:service.keyRequest.count.client:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"Key_request_Y~")"))))):splitBy("dt.entity.service_method"):avg:default(0)
*
builtin:service.keyRequest.response.time:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"Key_request_Y~")"))))):splitBy("dt.entity.service_method"):avg:default(0)
)
/
(
builtin:service.keyRequest.count.client:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"Key_request_X~")"))))):splitBy("dt.entity.service_method"):avg:default(0)
+
builtin:service.keyRequest.count.client:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"Key_request_Y~")"))))):splitBy("dt.entity.service_method"):avg:default(0)
))
Hope you a good monitoring!
23 Aug 2024 01:14 PM
Thank you @erh_inetum and @jaume_reverte for your answers. I tried both you answers and a few more on my own. Code seems to work just fine with no errors, but when i run the query i get no data. When i run the metrics individually i get the output im expecting. Any insights?
23 Aug 2024 02:01 PM
Welcome, Dimitris.
Do you have data for all metrics in the selected timeframe? If for any metric hasn't data maybe It was the reason for which you don't get data.
To avoid it, use default(0) fold.
Hope it helps.
Regards,
Elena
23 Aug 2024 02:07 PM
Thank you @erh_inetum. Yes i have data because for each individual metric of the key requests i see data. The problem is when i try to combine them. I used the default(0) as well.
Thanks,
Dimitris
23 Aug 2024 06:10 PM
Hi Dimitris,
If you have data in the whole timeframe for the two webrequest is not necessary you use fold transformation.
Have you be sure to put the brackets in the correct place?
It works and it returns data:
((
(builtin:service.keyRequest.response.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequestA~")"))))):median)
*
(builtin:service.keyRequest.count.total:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequestA~")"))))))
)
+
(
(builtin:service.keyRequest.response.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequestB~")"))))):median)
*
(builtin:service.keyRequest.count.total:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequestB~")"))))))
))
/
(
(builtin:service.keyRequest.count.total:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequestA~")"))))))
+
(builtin:service.keyRequest.count.total:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method),entityName.equals(~"keyrequestB~")"))))))
)
Hope it helps.
Regards,
Elena.
23 Aug 2024 07:48 PM - edited 26 Aug 2024 08:20 AM
Hello Elena (@erh_inetum) and Jaume (@jaume_reverte ) ,
I fixed the issue. It had to do with dimensions not being the same. I used the merge method to see data in my explorer. Here i will attach my code so that people can use it for future reference, if anyone comes across the same problem:
((
(
builtin:service.keyRequest.response.time:filter(and(in("dt.entity.service_method",entitySelector("type(service_method),entityId(~"Request_X~")")))):merge("dt.entity.service_method"):median
*
builtin:service.keyRequest.count.total:filter(and(in("dt.entity.service_method",entitySelector("type(service_method),entityId(~"Request_X~")")))):merge("dt.entity.service_method"):sum
)
+
(
builtin:service.keyRequest.response.time:filter(and(in("dt.entity.service_method",entitySelector("type(service_method),entityId(~"Request_Y~")")))):merge("dt.entity.service_method"):median
*
builtin:service.keyRequest.count.total:filter(and(in("dt.entity.service_method",entitySelector("type(service_method),entityId(~"Request_Y~")")))):merge("dt.entity.service_method"):sum
)
)
/
(
builtin:service.keyRequest.count.total:filter(and(in("dt.entity.service_method",entitySelector("type(service_method),entityId(~"Request_X~")")))):merge("dt.entity.service_method"):sum
+
builtin:service.keyRequest.count.total:filter(and(in("dt.entity.service_method",entitySelector("type(service_method),entityId(~"Request_Y~")")))):merge("dt.entity.service_method"):sum
) )
02 Sep 2024 01:29 PM - edited 02 Sep 2024 01:31 PM
Hello @erh_inetum and @jaume_reverte . One more quick question regarding the matter. Is there any way to get the absolute value of the metric we created above? cause i cant seem to find any function for that.
Thank you!
02 Sep 2024 02:24 PM
Hi Dimitris,
I think it's not possible for Data Explorer but with DQL you can do that using abs function
Regards,
Elena.
02 Sep 2024 02:28 PM
That's what i was afraid of. Unfortunately my client is on the Managed Enviroment, so there is no fix there.
Really appreciate your answer. Have a great day!