如何从Azure AppInsights分析访问自定义事件值?

时间:2019-11-11 15:33:07

标签: azure azure-application-insights

我正在向Azure报告一些自定义事件,该自定义事件中有一个值保存在名为“ totalTime”的customMeasurements对象下。

事件本身看起来像这样:

loading-time: {
    customMeasurements : { 
        totalTime: 123
    }
}

我正在尝试创建一个报告为每小时天蓝色的所有事件的平均总时间的图表。因此,我需要能够收集和平均事件中的值。

我似乎无法弄清楚如何从Azure AppInsights Analytics中访问customMeasurements值。这是Azure提供的一些代码。

union customEvents
| where timestamp between(datetime("2019-11-10T16:00:00.000Z")..datetime("2019-11-11T16:00:00.000Z"))
| where name == "loading-time"
| summarize Ocurrences=count() by bin(timestamp, 1h)
| order by timestamp asc
| render barchart

此代码仅计算过去24小时内报告的事件数,并每小时显示一次。

我尝试通过

访问事件中保存的customMeasurements对象
summarize Occurrences=avg(customMeasurements["totalTime"])

但是Azure不喜欢那样,所以我做错了。如何获得所需的值?我似乎也找不到任何文档。

1 个答案:

答案 0 :(得分:0)

将来自customDimensions / customMeasurements属性收集器的数据投影到新变量中,将用于进一步聚合,这很有用。通常,您需要使用 todecimal toint tostring 函数之一将尺寸数据转换为期望的类型。

例如,我对依赖遥测进行了一些额外的测量,因此我可以做类似的事情

dependencies
| project ["ResponseCompletionTime"] = todecimal(customMeasurements.ResponseToCompletion), timestamp 
| summarize avg(ResponseCompletionTime) by bin(timestamp, 1h) 

您的查询可能类似于

customEvents
| where timestamp between(datetime("2019-11-10T16:00:00.000Z")..datetime("2019-11-11T16:00:00.000Z"))
| where name == "loading-time"
| project ["TotalTime"] = toint(customMeasurements.totalTime), timestamp 
| summarize avg(TotalTime) by bin(timestamp, 1h)
| render barchart