如何在 Azure Monitor 中跨 Log Analytics 和 Application Insights 进行查询

How to Query Across Log Analytics and Application Insights in Azure Monitor

This answer 总结 App Insights (AI) 和 Log Analytics (LA) 正在合并为一项服务。它还提供了一个建议,AI中的新资源可以指向LA,这样你所有的代码都在一个地方。

我的问题是我如何查询 LA 和 AI 资源,假设两者都存在,并且您没有时间或权限将 AI 更改为指向 LA。

使用 Azure Workbooks 我意识到我可以从 LA 或 AI 内部的多个资源进行查询,但我似乎无法在一个单元格中跨 LA 和 AI 进行查询(也无法在单元格之间保存结果。)

目前我能想到的解决这个问题的唯一方法是通过API查询或加入PBI报告,但这两种方法对于完成探索性查询来说都是巨大的开销。有没有更简单的方法,最好是留在 Kusto 查询中?

Azure Monitor 是您的 one-stop 店铺,可在 cross-resources.

查询

Previously with Azure Monitor, you could only analyze data from within the current workspace, and it limited your ability to query across multiple workspaces defined in your subscription. Additionally, you could only search telemetry items collected from your web-based application with Application Insights directly in Application Insights or from Visual Studio. This also made it a challenge to natively analyze operational and application data together.

Now you can query not only across multiple Log Analytics workspaces, but also data from a specific Application Insights app in the same resource group, another resource group, or another subscription. This provides you with a system-wide view of your data. You can only perform these types of queries in Log Analytics.

要在查询中引用另一个工作区,请使用 workspace identifier, and for an app from Application Insights, use the app 标识符。

例如,您可以从您的任何资源实例中查询多个资源,这些资源可以是如下组合的工作区和应用程序。

// crossResource function that scopes my Application Insights resources
union withsource= SourceApp
app('Contoso-app1').requests, 
app('Contoso-app2').requests,
app('Contoso-app3').requests,
app('Contoso-app4').requests,
app('Contoso-app5').requests

或者喜欢,

union Update, workspace("contosoretail-it").Update, workspace("b459b4u5-912x-46d5-9cb1-p43069212nb4").Update
| where TimeGenerated >= ago(1h)
| where UpdateState == "Needed"
| summarize dcount(Computer) by Classification

或者喜欢,

applicationsScoping 
| where timestamp > ago(12h)
| where success == 'False'
| parse SourceApp with * '(' applicationName ')' * 
| summarize count() by applicationName, bin(timestamp, 1h) 
| render timechart

详情请参考this