我正在尝试根据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
,我不知道为什么自定义指标警报页面会给我这个错误。
我发现我的查询出了什么问题。从本质上讲,聚合值需要是数字,但是AggregatedValue=avg(timeDiff)
会产生时间值,但它只需几秒钟,因此有点难以注意到。将它转换为int解决了这个问题,
我刚刚更新了最后一位,如下所示
timeDiffs
| summarize AggregatedValue=toint(avg(timeDiff)/time(1ms)) by bin(timestamp, 5m)
这给Aggregate On
带来了另一个挑战,同时创建警报,因为AggregatedValue
不是by
声明之后的分组的一部分。