将 Azure Monitor 日志数据导入到 Power BI 中Import Azure Monitor log data into Power BI

Power BI 是 Microsoft 的一种基于云的业务分析服务,它为不同数据集的分析提供了丰富的可视化功能和报告。Power BI is a cloud based business analytics service from Microsoft that provides rich visualizations and reports for analysis of different sets of data. 你可以将 Azure Monitor 日志查询结果导入 Power BI 数据集,以便利用其各项功能,例如合并不同来源的数据,以及在 Web 和移动设备上共享报表。You can import the results of an Azure Monitor log query into a Power BI dataset so you can take advantage of its features such as combining data from different sources and sharing reports on the web and mobile devices.


本文最近已更新,从使用术语“Log Analytics”改为使用术语“Azure Monitor 日志”。This article was recently updated to use the term Azure Monitor logs instead of Log Analytics. 日志数据仍然存储在 Log Analytics 工作区中,并仍然由同一 Log Analytics 服务收集并分析。Log data is still stored in a Log Analytics workspace and is still collected and analyzed by the same Log Analytics service. 我们正在更新术语,以便更好地反映 Azure Monitor 中日志的角色。We are updating the terminology to better reflect the role of logs in Azure Monitor. 有关详细信息,请参阅 Azure Monitor 术语更改See Azure Monitor terminology changes for details.


若要将 Azure Monitor 中 Log Analytics 工作区的数据导入到 Power BI,可以基于 Azure Monitor 中的日志查询在 Power BI 中创建数据集。To import data from a Log Analytics workspace in Azure Monitor into Power BI, you create a dataset in Power BI based on a log query in Azure Monitor. 每次刷新数据集时都会运行查询。The query is run each time the dataset is refreshed. 随后你即可生成使用数据集中的数据的 Power BI 报表。You can then build Power BI reports that use data from the dataset. 若要在 Power BI 中创建数据集,你可以将查询从 Log Analytics 导出为 Power Query (M) 语言To create the dataset in Power BI, you export your query from Log Analytics to Power Query (M) language. 然后,你可以使用其在 Power BI Desktop 中创建查询,再将其作为数据集发布到 Power BI。You then use this to create a query in Power BI Desktop and then publish it to Power BI as a dataset. 此过程的详细信息如下所述。The details for this process are described below.

Log Analytics 到 Power BI

导出查询Export query

首先创建一个日志查询,该查询返回要填充 Power BI 数据集的数据。Start by creating a log query that returns the data that you want to populate the Power BI dataset. 随后将该查询导出为 Power BI Desktop 可以使用的 Power Query (M) 语言You then export that query to Power Query (M) language which can be used by Power BI Desktop.

  1. 在 Log Analytics 中创建日志查询以提取数据集的数据。Create the log query in Log Analytics to extract the data for your dataset.

  2. 选择“导出” > “导出到 Power BI (M 查询)” 。Select Export > Export to Power BI (M query). 这会将查询导出到名为 PowerBIQuery.txt 的文本文件中。This exports the query to a text file called PowerBIQuery.txt.


  3. 打开该文本文件并复制其内容。Open the text file and copy its contents.

将查询导入到 Power BI DesktopImport query into Power BI Desktop

Power BI Desktop 是一个桌面应用程序,用于创建可发布到 Power BI 的数据集和报表。Power BI Desktop is a desktop application that allows you to create datasets and reports that can be published to Power BI. 还可以通过它使用从 Azure Monitor 导出的 Power Query 语言创建查询。You can also use it to create a query using the Power Query language exported from Azure Monitor.

  1. 请安装 Power BI Desktop(如果你尚未安装),然后打开该应用程序。Install Power BI Desktop if you don't already have it and then open the application.

  2. 选择“获取数据” > “空查询”,以打开一个新查询。Select Get Data > Blank Query to open a new query. 然后选择“高级编辑器”并将导出文件的内容粘贴到查询中。Then select Advanced Editor and paste the contents of the exported file into the query. 单击“Done”(完成) 。Click Done.

    Power BI Desktop 查询

  3. 查询将运行并显示其结果。The query runs, and its results are displayed. 系统可能会提示你输入凭据以连接到 Azure。You may be prompted for credentials to connect to Azure.

  4. 为查询键入一个描述性的名称。Type in a descriptive name for the query. 默认值为“Query1”。The default is Query1. 单击“关闭并应用”,以向报表添加数据集。Click Close and Apply to add the dataset to the report.

    Power BI Desktop

发布到 Power BIPublish to Power BI

当你发布到 Power BI 时,将创建数据集和报表。When you publish to Power BI, a dataset and a report will be created. 如果你是在 Power BI Desktop 中创建报表,则发布的报表将包含你的数据。If you create a report in Power BI Desktop, then this will be published with your data. 如果不是,则会创建一个空白报表。If not, then a blank report will be created. 你可以在 Power BI 中修改报表或基于数据集创建新报表。You can modify the report in Power BI or create a new one based on the dataset.

  1. 基于你的数据创建报表。Create a report based on your data. 请使用 Power BI Desktop 文档(如果你不熟悉此应用程序)。Use Power BI Desktop documentation if you're not familiar with it.

  2. 如果你已准备好将其发送到 Power BI,请单击“发布”。When you're ready to send it to Power BI, click Publish.

  3. 出现提示时,请在 Power BI 帐户中选择目标。When prompted, select a destination in your Power BI account. 除非你有特定的目标,否则请使用“我的工作区”。Unless you have a specific destination in mind, use My workspace.

    Power BI Desktop 发布

  4. 发布完成后,单击“在 Power BI 中打开”,以在 Power BI 中打开新数据集。When the publishing completes, click Open in Power BI to open Power BI with your new dataset.

配置计划的刷新Configure scheduled refresh

在 Power BI 中创建的数据集中包含的数据与你以前在 Power BI Desktop 中看到的数据一样。The dataset created in Power BI will have the same data that you previously saw in Power BI Desktop. 你需要定期刷新数据集以再次运行查询,并使用 Azure Monitor 中的最新数据进行填充。You need to refresh the dataset periodically to run the query again and populate it with the latest data from Azure Monitor.

  1. 单击要在其中上传报表的工作区并选择“数据集”菜单。Click on the workspace where you uploaded your report and select the Datasets menu.

  2. 选择你的新数据集旁边的上下文菜单,然后选择“设置”。Select the context menu next to your new dataset and select Settings.

  3. 在“数据源凭据”下,应显示一条消息,提示凭据无效。Under Data source credentials you should have a message that the credentials are invalid. 这是因为你尚未提供在刷新数据时要使用的数据集的凭据。This is because you haven't provided credentials yet for the dataset to use when it refreshes its data.

  4. 单击“编辑凭据”并指定有权访问 Azure Monitor 中的 Log Analytics 工作区的凭据。Click Edit credentials and specify credentials with access to the Log Analytics workspace in Azure Monitor. 如果需要双因素身份验证,请选择“OAuth2”作为使用凭据登录时要提示的身份验证方法If you require two-factor authentication, select OAuth2 for the Authentication method to be prompted to login with your credentials.

    Power BI 计划

  5. 在“计划的刷新”下,开启“使你的数据保持为最新”选项。Under Scheduled refresh turn on the option to Keep your data up to date. 你可以视情况更改“刷新频率”和运行刷新的一个或多个特定时间。You can optionally change the Refresh frequency and one or more specific times to run the refresh.

    Power BI 刷新

后续步骤Next steps

  • 了解有关日志搜索的信息以生成可导出到 Power BI 的查询。Learn about log searches to build queries that can be exported to Power BI.
  • 详细了解 Power BI 以基于 Azure Monitor 日志导出内容生成可视化结果。Learn more about Power BI to build visualizations based on Azure Monitor log exports.