Application Insights查询比平常更高

时间:2017-11-10 12:03:01

标签: azure-application-insights azure-log-analytics

我正在尝试在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")

但是,我想要做的是将硬编码的“500”值替换为可能从其他Google Analytics查询生成的动态值。例如,我可能希望确保最后小时中90%(或其他)查​​询的响应时间小于上一次

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

    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")

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

感谢您的帮助。

1 个答案:

答案 0 :(得分: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") 

enter image description here