1

我正在尝试在 Azure Application Insights Analytics 中编写一个自定义查询,该查询将检查某个请求计时器指标是否比以前更大。

我可以使用以下查询轻松编写一个查询,检查请求时间是否在过去一小时内 90% 的时间内低于 500 毫秒。如果已经通过,它将返回。

    requests
| where timestamp >= ago(1hour)
| where (itemType == 'request' and (tostring(customDimensions['RequestName']) == 'TestRequest' 
| extend responseTime = tolong(customDimensions['totalMilliseconds']) 
| summarize isPassed = (percentile(responseTime, 90) < 500)
| project iff(isPassed, "PASSED", "FAILED")

但是,我想做的是用可能从另一个 Analytics 查询生成的动态值替换硬编码的“500”值。例如,我可能想确保最后一小时内 90%(或其他)查​​询响应时间小于上个月90% 查询的响应时间。

我可以通过更改 ago 方法中的值然后不进行通过/失败检查来复制上述查询来实现这个新查询:

    requests
| where timestamp >= ago(30day)
| where (itemType == 'request' and (tostring(customDimensions['RequestName']) == 'TestRequest' 
| extend responseTime = tolong(customDimensions['totalMilliseconds']) 
| summarize percentile(responseTime, 90)

我不确定如何将这两个查询一起运行,例如保存第二个查询的输出以在第一个查询中使用。这样的事情是我试图实现的目标:

  requests
| where timestamp >= ago(30day)
| where (itemType == 'request' and (tostring(customDimensions['RequestName']) == 'TestRequest' 
| extend responseTime = tolong(customDimensions['totalMilliseconds']) 
| X = summarize percentile(responseTime, 90)
   requests
    | where timestamp >= ago(1hour)
    | where (itemType == 'request' and (tostring(customDimensions['RequestName']) == 'TestRequest' 
    | extend responseTime = tolong(customDimensions['totalMilliseconds']) 
    | summarize isPassed = (percentile(responseTime, 90) < X)
    | project iff(isPassed, "PASSED", "FAILED")

如果有人能指出我如何实现这一目标的方向,将不胜感激。

谢谢你的帮助。

4

1 回答 1

1

这应该有一个技巧:

let threshold = toscalar(requests
| where timestamp > ago(30d)
| summarize percentile(duration, 90));
requests
| where timestamp > ago(1h)
| summarize percentile90 = percentile(duration, 90)
| extend isPassed = percentile90 < threshold
| project Result=iff(isPassed, "PASSED", "FAILED") 

在此处输入图像描述

于 2017-11-10T17:23:00.670 回答