对于指标警报类型,搜索查询应包含“ AggregatedValue”和“ bin(timestamp,[roundTo])”

时间:2018-09-17 10:10:25

标签: azure azure-devops azure-application-insights

我正在尝试根据Application Insights日志中的某些指标创建自定义指标警报。以下是我正在使用的查询;

let start = customEvents
| where customDimensions.configName == "configName" 
| where name == "name"
| extend timestamp, correlationId = tostring(customDimensions.correlationId), configName = tostring(customDimensions.configName);

let ending = customEvents
| where customDimensions.configName == configName" 
| where name == "anotherName" 
| where customDimensions.taskName == "taskName" 
| extend timestamp, correlationId = tostring(customDimensions.correlationId), configName = tostring(customDimensions.configName), name= name, nameTimeStamp= timestamp ;


let timeDiffs = start
| join (ending) on correlationId
| extend timeDiff = nameTimeStamp- timestamp
| project timeDiff, timestamp, nameTimeStamp, name, anotherName, correlationId;

timeDiffs
| summarize AggregatedValue=avg(timeDiff) by bin(timestamp, 1m)

在Google Analytics(分析)页面中运行此查询时,我得到了结果,但是当我尝试创建自定义指标警报时,却收到了错误Search Query should contain 'AggregatedValue' and 'bin(timestamp, [roundTo])' for Metric alert type

我发现的唯一响应是添加已经拥有的AggregatedValue,我不确定为什么自定义指标警报页面会给我这个错误。

1 个答案:

答案 0 :(得分:1)

我发现查询出了什么问题。本质上,合计值需要为数字,但是AggregatedValue=avg(timeDiff)会产生时间值,但以秒为单位,因此有点难以注意到。将其转换为int即可解决问题,

我刚刚更新了以下内容

timeDiffs
| summarize AggregatedValue=toint(avg(timeDiff)/time(1ms)) by bin(timestamp, 5m)

在创建警报时,Aggregate On面临另一个挑战,因为AggregatedValue不属于by语句之后的分组。