创建和共享 Log Analytics 数据的仪表板Create and share dashboards of Log Analytics data

Log Analytics 仪表板可直观显示所有已保存的日志查询,使你能够在组织中查找、关联和共享 IT 操作数据。Log Analytics dashboards can visualize all of your saved log queries, giving you the ability to find, correlate, and share IT operational data in the organization. 本教程介绍如何创建日志查询,以用于支持 IT 操作支持团队要访问的共享仪表板。This tutorial covers creating a log query that will be used to support a shared dashboard that will be accessed by your IT operations support team. 你将学习如何执行以下操作:You learn how to:

  • 在 Azure 门户中创建共享仪表板Create a shared dashboard in the Azure portal
  • 直观显示性能日志查询Visualize a performance log query
  • 将日志查询添加到共享仪表板Add a log query to a shared dashboard
  • 在共享仪表板中自定义磁贴Customize a tile in a shared dashboard

要完成本教程中的示例,必须将现有虚拟机连接到 Log Analytics 工作区To complete the example in this tutorial, you must have an existing virtual machine connected to the Log Analytics workspace.

登录到 Azure 门户Sign in to Azure portal

https://portal.azure.cn 中登录 Azure 门户。Sign in to the Azure portal at https://portal.azure.cn.

创建共享仪表板Create a shared dashboard

选择“仪表板” 以打开默认仪表板Select Dashboard to open your default dashboard. 你的仪表板看起来与下面的示例有所不同。Your dashboard will look different than the example below.

Azure 门户仪表板

可将所有 Azure 资源中对 IT 而言最重要的操作数据整合到此处,包括来自 Azure Log Analytics 的遥测数据。Here you can bring together operational data that is most important to IT across all your Azure resources, including telemetry from Azure Log Analytics. 在开始直观显示日志查询之前,先来创建并共享一个仪表板。Before we step into visualizing a log query, let's first create a dashboard and share it. 然后,可以专注于将呈现为折线图的示例性能日志查询,并将其添加到该仪表板。We can then focus on our example performance log query, which will render as a line chart, and add it to the dashboard.

若要创建仪表板,请选择当前仪表板名称旁边的“新建仪表板” 按钮。To create a dashboard, select the New dashboard button next to the current dashboard's name.

在 Azure 门户中新建仪表板

此操作会创建全新的专用空仪表板,并进入自定义模式,可在此模式下命名仪表板以及添加或重新排列磁贴。This action creates a new, empty, private dashboard and puts you into customization mode where you can name your dashboard and add or rearrange tiles. 编辑仪表板的名称,指定用于本教程的“示例仪表板”,然后选择“完成自定义” 。Edit the name of the dashboard and specify Sample Dashboard for this tutorial, and then select Done customizing.

保存自定义的 Azure 仪表板Save customized Azure dashboard

创建仪表板时,默认该仪表板是专用的,这意味着只有你才可以看到它。When you create a dashboard, it is private by default, which means you are the only person who can see it. 若要让其对其他人可见,请使用与其他仪表板命令一起出现的“共享” 按钮。To make it visible to others, use the Share button that appears alongside the other dashboard commands.

在 Azure 门户中共享新的仪表板

系统会要求选择可将仪表板发布到的订阅和资源组。You are asked to choose a subscription and resource group for your dashboard to be published to. 为方便起见,门户的发布体验会引导完成将仪表板放在名为仪表板的资源组中的模式。For convenience, the portal's publishing experience guides you towards a pattern where you place dashboards in a resource group called dashboards. 验证所选订阅,然后单击“发布” 。Verify the subscription selected and then click Publish. 通过 Azure 基于资源的访问控制来控制对仪表板中所显示信息的访问。Access to the information displayed in the dashboard is controlled with Azure Resource Based Access Control.

直观显示日志查询Visualize a log query

Log Analytics 是一个用于处理日志查询及其结果的专用门户。Log Analytics is a dedicated portal used to work with log queries and their results. 这些功能包括在多行上编辑查询、选择性地执行代码、上下文相关 Intellisense 和智能分析。Features include the ability to edit a query on multiple lines, selectively execute code, context sensitive Intellisense, and Smart Analytics. 在本教程中,你将使用 Log Analytics 创建图形形式的性能视图,将其保存以供将来查询,并将其固定到之前创建的共享仪表板。In this tutorial, you will use Log Analytics to create a performance view in graphical form, save it for a future query, and pin it to the shared dashboard created earlier.

在“Azure Monitor”菜单中选择“日志” 以打开 Log Analytics。Open Log Analytics by selecting Logs in the Azure Monitor menu. 它将启动并显示一个新的空白查询。It starts with a new blank query.

主页

输入以下查询来返回 Windows 和 Linux 计算机的处理器利用率记录,这些记录按“计算机”和 TimeGenerated 分组并显示在可视图表中。Enter the following query to return processor utilization records for both Windows and Linux computers, grouped by Computer and TimeGenerated, and displayed in a visual chart. 单击“运行” 以运行该查询,并查看生成的图表。Click Run to run the query and view the resulting chart.

Perf 
| where CounterName == "% Processor Time" and ObjectName == "Processor" and InstanceName == "_Total" 
| summarize AggregatedValue = avg(CounterValue) by bin(TimeGenerated, 1hr), Computer 
| render timechart

选择页面顶部的“保存”按钮,以保存查询 。Save the query by selecting the Save button from the top of the page.

保存查询

在“保存查询”控制面板中提供名称(例如“Azure VM - 处理器利用率”)和类别(例如“仪表板”),然后单击“保存” 。In the Save Query control panel, provide a name such as Azure VMs - Processor Utilization and a category such as Dashboards and then click Save. 这样,便可创建可以使用和修改的常见查询的库。This way you can create a library of common queries that you can use and modify. 最后,从页面右上角选择“固定”按钮,然后再选择仪表板名称,以将其固定到之前创建的共享仪表板 。Finally, pin this to the shared dashboard created earlier by selecting the Pin button from the top right corner of the page and then selecting the dashboard name.

将查询固定到仪表板之后,可发现该查询下方有一个通用标题和注释。Now that we have a query pinned to the dashboard, you will notice it has a generic title and comment below it.

Azure 仪表板示例

应将其重命名为查看者易于理解的、富有意义的名称。We should rename it to something meaningful that can be easily understood by those viewing it. 单击“编辑”按钮以自定义磁贴的标题和副标题,然后单击“更新” 。Click the edit button to customize the title and subtitle for the tile, and then click Update. 随即会出现询问你是发布更改还是放弃的横幅。A banner will appear asking you to publish changes or discard. 单击“保存副本” 。Click Save a copy.

已完成的示例仪表板配置

后续步骤Next steps

本教程介绍了如何在 Azure 门户中创建仪表板并向其中添加日志查询。In this tutorial, you learned how to create a dashboard in the Azure portal and add a log query to it. 请继续学习下一教程以了解可根据日志查询结果实现的不同响应。Advance to the next tutorial to learn the different responses you can implement based on log query results.