在Application Insights分析中,如何查询特定异常影响的用户百分比?

时间:2018-04-03 08:53:26

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

我使用此查询来显示异常:

exceptions
| where application_Version == "xyz"
| summarize count_=count(itemCount), impactedUsers=dcount(user_Id) by problemId, type, method, outerMessage, innermostMessage
| order by impactedUsers 

如何查询特定异常影响的用户百分比?

我会通过此查询检查所有用户:

customEvents
| where application_Version == "xyz" 
| summarize dcount(user_Id) 

1 个答案:

答案 0 :(得分:1)

你几乎就拥有了你所拥有的东西,你只需要连接两者:

  1. 使用let + toscalar将查询结果定义为数字
  2. 在你的查询中引用(我使用*1.0强制它成为一个浮点数,否则你得到0,用round得到2个小数,然后根据需要调整)
  3. 进行查询:

    let totalUsers = toscalar(customEvents
     | where application_Version == "xyz" 
     | summarize dcount(user_Id));
     exceptions
     | where application_Version == "xyz"
     | summarize count_=count(itemCount), 
          impactedUsers=dcount(user_Id), 
          percent=round(dcount(user_Id)*1.0/totalUsers*100.0,2) 
       by problemId, type, method, outerMessage, innermostMessage
     | order by impactedUsers