从 Application Insights 向 Power BI 馈送数据Feed Power BI from Application Insights

Power BI 是一套商业工具,可帮助分析数据及分享见解。Power BI is a suite of business tools that helps you analyze data and share insights. 每个设备上都提供了丰富的仪表板。Rich dashboards are available on every device. 可以结合许多源的数据,包括来自 Azure Application Insights 的数据。You can combine data from many sources, including Analytics queries from Azure Application Insights.

可以使用三种方法将 Application Insights 数据导出到 Power BI:There are three methods of exporting Application Insights data to Power BI:

  • 导出 Analytics 查询Export Analytics queries. 这是首选方法。This is the preferred method. 编写任何所需的查询,并将其导出到 Power BI。Write any query you want and export it to Power BI. 可将此查询连同其他所有数据一起放置在仪表板上。You can place this query on a dashboard, along with any other data.
  • 连续导出和 Azure 流分析Continuous export and Azure Stream Analytics. 如果希望长时间存储数据,则此方法非常有用。This method is useful if you want to store your data for long periods of time. 如果没有较长的数据保留要求,请使用“导出 Analytics 查询”方法。If you don't have an extended data retention requirement, use the export analytics query method. “连续导出和流分析”需要执行更多工作来进行设置,并且存储开销更大。Continuous export and Stream Analytics involves more work to set up and additional storage overhead.
  • Power BI 适配器Power BI adapter. 图表集是预定义的,但可以从其他源任何添加自己的查询。The set of charts is predefined, but you can add your own queries from any other sources.

备注

Power BI 适配器现在已弃用The Power BI adapter is now deprecated. 此解决方案的预定义图表是由静态的不可编辑查询填充的。The predefined charts for this solution are populated by static uneditable queries. 你无法编辑这些查询,到 Power BI 的连接可能会成功但不会填充数据,具体取决于你的数据的某些属性。You do not have the ability to edit these queries and depending on certain properties of your data it is possible for the connection to Power BI to be successful, but no data is populated. 这是由硬编码的查询中设置的排除条件导致的。This is due to exclusion criteria that are set within the hardcoded query. 虽然此解决方案仍然适用于某些客户,但是由于缺少适配器的灵活性,建议的解决方案是使用导出 Analytics 查询功能。While this solution may still work for some customers, due to the lack of flexibility of the adapter the recommended solution is to use the export Analytics query functionality.

导出 Analytics 查询Export Analytics queries

可以使用这种方法编写所需的任何 Analytics 查询或从使用情况漏斗图导出,然后将其导出到 Power BI 仪表板。This route allows you to write any Analytics query you like, or export from Usage Funnels, and then export that to a Power BI dashboard. (可以添加到适配器创建的仪表板。)(You can add to the dashboard created by the adapter.)

一次性操作:安装 Power BI DesktopOne time: install Power BI Desktop

若要导入 Application Insights 查询,可以使用 Power BI Desktop(桌面版)。To import your Application Insights query, you use the desktop version of Power BI. 随后可以将其发布到 Web 或 Power BI 云工作区。Then you can publish it to the web or to your Power BI cloud workspace.

安装 Power BI DesktopInstall Power BI Desktop.

导出 Analytics 查询Export an Analytics query

  1. 打开 Analytics 并编写查询Open Analytics and write your query.

  2. 测试并优化查询,直到对结果满意。Test and refine the query until you're happy with the results. 导出之前,请确保查询在 Analytics 中正常运行。Make sure that the query runs correctly in Analytics before you export it.

  3. 在“导出”菜单中,选择“Power BI (M)”。 On the Export menu, choose Power BI (M). 保存文本文件。Save the text file.

    Analytics 屏幕截图,其中突出显示了“导出”菜单

  4. 在 Power BI Desktop 中,选择“获取数据” > “空白查询”。In Power BI Desktop, select Get Data > Blank Query. 然后,在查询编辑器中的“视图”下面,选择“高级查询编辑器”。 Then, in the query editor, under View, select Advanced Editor.

    将导出的 M 语言脚本粘贴到高级编辑器中。Paste the exported M Language script into the Advanced Editor.

    Power BI Desktop 的屏幕截图,其中突出显示了“高级编辑器”

  5. 可能需要提供凭据才能让 Power BI 访问 Azure。To allow Power BI to access Azure, you might have to provide credentials. 使用“组织帐户”和 Microsoft 帐户登录。Use Organizational account to sign in with your Microsoft account.

    Power BI“查询设置”对话框的屏幕截图

    如果需要验证凭据,请使用查询编辑器中的“数据源设置”菜单命令。If you need to verify the credentials, use the Data Source Settings menu command in the query editor. 请务必指定用于 Azure 的凭据,它可能不同于用于 Power BI 的凭据。Be sure to specify the credentials you use for Azure, which might be different from your credentials for Power BI.

  6. 选择查询的可视化效果并选择 X 轴、Y 轴和分段维度的字段。Choose a visualization for your query, and select the fields for x-axis, y-axis, and segmenting dimension.

    Power BI Desktop 可视化选项的屏幕截图

  7. 将报告发布到 Power BI 云工作区。Publish your report to your Power BI cloud workspace. 在该工作区中,可将同步的版本嵌入其他网页。From there, you can embed a synchronized version into other web pages.

    Power BI Desktop 的屏幕截图,其中突出显示了“发布”按钮

  8. 定期手动刷新报告,或者在选项页中设置按计划刷新。Refresh the report manually at intervals, or set up a scheduled refresh on the options page.

导出漏斗图Export a Funnel

  1. 生成漏斗图Make your Funnel.

  2. 选择“Power BI”。Select Power BI.

    Power BI 按钮的屏幕截图

  3. 在 Power BI Desktop 中,选择“获取数据” > “空白查询”。In Power BI Desktop, select Get Data > Blank Query. 然后,在查询编辑器中的“视图”下面,选择“高级查询编辑器”。 Then, in the query editor, under View, select Advanced Editor.

    Power BI Desktop 的屏幕截图,其中突出显示了“空白查询”按钮

    将导出的 M 语言脚本粘贴到高级编辑器中。Paste the exported M Language script into the Advanced Editor.

    Power BI Desktop 的屏幕截图,其中突出显示了“高级编辑器”

  4. 从查询中选择项并选择“漏斗图可视化效果”。Select items from the query, and choose a Funnel visualization.

    Power BI Desktop 可视化选项的屏幕截图

  5. 更改标题使其有意义,并将报表发布到 Power BI 云工作区。Change the title to make it meaningful, and publish your report to your Power BI cloud workspace.

    Power BI Desktop 的屏幕截图,其中突出显示了标题更改

故障排除Troubleshooting

你可能会遇到与凭据或数据集大小相关的错误。You might encounter errors pertaining to credentials or the size of the dataset. 下面是有关如何解决这些错误的一些信息。Here is some information about what to do about these errors.

未授权(401 或 403)Unauthorized (401 or 403)

若未更新过刷新令牌,可能会出现此问题。This can happen if your refresh token has not been updated. 请尝试以下步骤,确保仍拥有访问权限:Try these steps to ensure you still have access:

  1. 登录 Azure 门户,确保可访问资源。Sign in to the Azure portal, and make sure you can access the resource.

  2. 尝试刷新仪表板的凭据。Try to refresh the credentials for the dashboard.

  3. 尝试从 PowerBI Desktop 清除缓存。Try to clear the cache from your PowerBI Desktop.

    如果具有访问权限且刷新凭据不起作用,请开具支持票证。If you do have access and refreshing the credentials does not work, please open a support ticket.

错误的网关 (502)Bad Gateway (502)

这通常由返回过多数据的分析查询导致。This is usually caused by an Analytics query that returns too much data. 尝试使用较小的时间范围执行查询。Try using a smaller time range for the query.

如果减少来自分析查询的数据集不符合需求,应考虑使用 API 来拉取更大的数据集。If reducing the dataset coming from the Analytics query doesn't meet your requirements, consider using the API to pull a larger dataset. 下面介绍如何转换 M-Query 导出以使用 API。Here's how to convert the M-Query export to use the API.

  1. 创建 API 密钥Create an API key.
  2. 通过将 Azure 资源管理器 URL 替换为 Application Insights API,更新从分析中导出的 Power BI M 脚本。Update the Power BI M script that you exported from Analytics by replacing the Azure Resource Manager URL with the Application Insights API.
    • https://management.chinacloudapi.cn/subscriptions/...Replace https://management.chinacloudapi.cn/subscriptions/...
    • 替换为 https://api.applicationinsights.io/beta/apps/...with, https://api.applicationinsights.io/beta/apps/...
  3. 最后,将凭据更新为基本凭据,再使用 API 密钥。Finally, update the credentials to basic, and use your API key.

现有脚本Existing script

Source = Json.Document(Web.Contents("https://management.chinacloudapi.cn/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups//providers/microsoft.insights/components//api/query?api-version=2014-12-01-preview",[Query=[#"csl"="requests",#"x-ms-app"="AAPBI"],Timeout=#duration(0,0,4,0)]))

更新的脚本Updated script

Source = Json.Document(Web.Contents("https://api.applicationinsights.io/beta/apps/<APPLICATION_ID>/query?api-version=2014-12-01-preview",[Query=[#"csl"="requests",#"x-ms-app"="AAPBI"],Timeout=#duration(0,0,4,0)]))

关于采样About sampling

根据应用程序发送的数据量,你可能希望使用自适应采样功能,它只发送一定百分比的遥测数据。Depending on the amount of data sent by your application, you might want to use the adaptive sampling feature, which sends only a percentage of your telemetry. 如果在 SDK 中或者针对引入手动设置了采样,也同样可以做到这一点。The same is true if you have manually set sampling either in the SDK or on ingestion. 了解有关采样的详细信息Learn more about sampling.

Power BI 适配器(已弃用)Power BI adapter (deprecated)

此方法可以自动创建完整的遥测仪表板。This method creates a complete dashboard of telemetry for you. 初始数据集是预定义的,但可以在其中添加更多数据。The initial dataset is predefined, but you can add more data to it.

获取适配器Get the adapter

  1. 登录 Power BISign in to Power BI.

  2. 打开“获取数据”左下角的“获取数据”图标的屏幕截图,然后选择“服务” 。Open Get Data Screenshot of GetData Icon in lower left corner, Services.

    从 Application Insights 数据源获取数据的屏幕截图

  3. 选择 Application Insights 下的“立即获取”。Select Get it now under Application Insights.

    从 Application Insights 数据源获取数据的屏幕截图

  4. 提供 Application Insights 资源的详细信息,然后登录Provide the details of your Application Insights resource, and then Sign-in.

    从 Application Insights 数据源获取数据的屏幕截图

    可以在 Application Insights 概述窗格中找到此信息:This information can be found in the Application Insights Overview pane:

    从 Application Insights 数据源获取数据的屏幕截图

  5. 打开新创建的 Application Insights Power BI 应用。Open the newly created Application Insights Power BI App.

  6. 等待一两分钟来导入数据。Wait a minute or two for the data to be imported.

    Power BI 适配器的屏幕截图

可以编辑仪表板,将 Application Insights 图表与其他源的图表以及 Analytics 查询合并在一起。You can edit the dashboard, combining the Application Insights charts with those of other sources, and with Analytics queries. 可以在可视化库获取更多图表,其中每个图表都包含可以设置的参数。You can get more charts in the visualization gallery, and each chart has parameters you can set.

完成初始导入后,仪表板和报告会持续每日更新。After the initial import, the dashboard and the reports continue to update daily. 可以控制数据集的刷新计划。You can control the refresh schedule on the dataset.

后续步骤Next steps