【问题标题】:How can I access custom event values from Azure AppInsights analytics?如何从 Azure AppInsights 分析访问自定义事件值?
【发布时间】:2019-11-11 15:33:07
【问题描述】:

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

事件本身如下所示:

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

我正在尝试创建一个图表,显示每小时报告给 azure 的所有事件的平均总时间。所以我需要能够收集和平均事件中的值。

我似乎不知道如何从 Azure AppInsights Analytics 中访问 c​​ustomMeasurements 值。这是 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 不喜欢这样,所以我做错了。如何访问我需要的值?我似乎也找不到任何文档。

【问题讨论】:

    标签: azure azure-application-insights


    【解决方案1】:

    将来自 customDimensions / customMeasurements 属性集合的数据投影到一个新变量中会很有用,您将使用该变量进行进一步聚合。您通常需要使用 todecimaltointtostring 函数之一将维度数据转换为预期类型。

    例如,我对依赖遥测有一些额外的测量,所以我可以这样做

    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
    

    【讨论】:

    • 感谢 Dylan,这符合我的预期。我也可以问一下在投影总时间时方括号的原因是什么?例如。 ["TotalTime"]。另外,我正在尝试通过执行extend email=tostring(customDimensions.teacherEmail) 来预测customDimensions 对象中保存的email 的值,但它要求我确保email is indeed a simple name,任何想法这里出了什么问题?
    • 带有引号和括号的["syntax"] 允许您创建/引用名称中带有特殊字符的字段,例如["some thing with spaces"]["Period.Delimited.Name"]。在这种情况下没有专门使用,但很高兴知道。
    猜你喜欢
    • 2017-10-24
    • 1970-01-01
    • 2019-01-24
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    相关资源
    最近更新 更多