使用 Azure Application Insights 创建自定义 KPI 仪表板Create custom KPI dashboards using Azure Application Insights

你可以在 Azure 门户中创建多个仪表板,每个仪表板都包含跨不同资源组和订阅可视化多个 Azure 资源数据的磁贴。You can create multiple dashboards in the Azure portal that each include tiles visualizing data from multiple Azure resources across different resource groups and subscriptions. 你可以从 Azure Application Insights 中固定不同的图表和视图,以创建自定义仪表板,为你提供应用程序运行状况和性能的完整画面。You can pin different charts and views from Azure Application Insights to create custom dashboards that provide you with complete picture of the health and performance of your application. 本教程将引导你完成自定义仪表板的创建,其中包括来自 Azure Application Insights 的多种类型的数据和可视化内容。This tutorial walks you through the creation of a custom dashboard that includes multiple types of data and visualizations from Azure Application Insights.

学习如何:You learn how to:

  • 在 Azure 中创建自定义仪表板Create a custom dashboard in Azure
  • 从磁贴库添加磁贴Add a tile from the Tile Gallery
  • 将 Application Insights 中的标准指标添加到仪表板Add standard metrics in Application Insights to the dashboard
  • 将 Application Insights 中的自定义指标图标添加到仪表板Add a custom metric chart Application Insights to the dashboard
  • 将日志(分析)查询的结果添加到仪表板Add the results of a Logs (Analytics) query to the dashboard

必备条件Prerequisites

完成本教程:To complete this tutorial:

备注

了解仪表板的访问控制一文中讨论了使用仪表板所需的权限。Required permissions for working with dashboards are discussed in the article on understanding access control for dashboards.

登录 AzureSign in to Azure

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

创建新的仪表板Create a new dashboard

警告

如果将 Application Insights 资源移至其他资源组或订阅,则需要手动更新仪表板,方法是删除旧磁贴并将同一 Application Insights 资源中的新磁贴固定在新位置。If you move your Application Insights resource over to a different resource group or subscription, you will need to manually update the dashboard by removing the old tiles and pinning new tiles from the same Application Insights resource at new location.

单个仪表板可以包含来自多个应用程序、资源组和订阅的资源。A single dashboard can contain resources from multiple applications, resource groups, and subscriptions. 通过为应用程序创建新的仪表板开始本教程。Start the tutorial by creating a new dashboard for your application.

  1. 在 Azure 门户左侧的菜单下拉列表中,选择“仪表板”。In the menu dropdown on the left in Azure portal, select Dashboard.

    Azure 门户菜单下拉列表

  2. 在仪表板窗格中,选择“新建仪表板”,然后选择“空白仪表板” 。On the dashboard pane, select New dashboard then Blank dashboard.

    新建仪表板

  3. 键入仪表板的名称。Type a name for the dashboard.

  4. 查看“磁贴库”,获取可以添加到仪表板中的各种磁贴。Have a look at the Tile Gallery for a variety of tiles that you can add to your dashboard. 除了从库添加磁贴之外,还可以将 Application Insights 中的图表和其他视图直接固定到仪表板。In addition to adding tiles from the gallery, you can pin charts and other views directly from Application Insights to the dashboard.

  5. 找到“Markdown”磁贴,并将其拖动到仪表板中。Locate the Markdown tile and drag it on to your dashboard. 该磁贴允许添加 markdown 格式的文本,这对于向仪表板添加描述性文本而言是理想选择。This tile allows you to add text formatted in markdown, which is ideal for adding descriptive text to your dashboard. 若要了解详细信息,请参阅在 Azure 仪表板上使用 Markdown 磁贴显示自定义内容To learn more, see Use a markdown tile on Azure dashboards to show custom content.

  6. 将文本添加到磁贴属性,然后在仪表板画布上调整其大小。Add text to the tile's properties and resize it on the dashboard canvas.

    编辑 markdown 磁贴Edit markdown tile

  7. 选择屏幕顶部的“完成自定义”以退出自定义模式。Select Done customizing at the top of the screen to exit tile customization mode.

添加运行状况概述Add health overview

包含静态文本的仪表板并不是很有趣,所以现在从 Application Insights 添加磁贴,以显示有关应用程序的信息。A dashboard with static text isn't very interesting, so now add a tile from Application Insights to show information about your application. 你可以从“磁贴库”添加 Application Insights 磁贴,也可以直接从“Application Insights”屏幕固定它们。You can add Application Insights tiles from the Tile Gallery, or you can pin them directly from Application Insights screens. 该操作允许将已经熟悉的图表和视图固定到仪表板之前对其进行配置。This allows you to configure charts and views that you're already familiar with before pinning them to your dashboard. 首先添加应用程序的标准运行状况概述。Start by adding the standard health overview for your application. 这不需要进行配置,并允许在仪表板中进行最起码的自定义操作。This requires no configuration and allows minimal customization in the dashboard.

  1. 在主屏幕上选择你的 Application Insights 资源。Select your Application Insights resource on the home screen.

  2. 在“概述”窗格中,选择图钉图标图钉图标,将磁贴添加到仪表板。In the Overview pane, select the pin icon pin icon to add the tile to a dashboard.

  3. 在“固定到仪表板”选项卡中,选择要向其中添加磁贴的仪表板,或创建新的仪表板。In the "Pin to dashboard" tab, select which dashboard to add the tile to or create a new one.

  4. 右上角将显示一条通知,指出你的磁贴已固定到仪表板上。In the top right, a notification will appear that your tile was pinned to your dashboard. 选择通知中的“已固定到仪表板”以返回到仪表板或使用仪表板窗格。Select Pinned to dashboard in the notification to return to your dashboard or use the dashboard pane.

  5. 该磁贴现在已添加到仪表板。That tile is now added to your dashboard. 选择“编辑”以更改磁贴的位置。Select Edit to change the positioning of the tile. 选择并将其拖动至相应位置,然后选择“完成自定义”。Select and drag it into position and then select Done customizing. 仪表板现在具有包含一些有用信息的磁贴。Your dashboard now has a tile with some useful information.

    编辑模式下的仪表板Dashboard in edit mode

添加自定义指标图表Add custom metric chart

“指标”面板允许你逐渐将 Application Insights 收集的指标绘入图表,筛选器和分组为可选内容。The Metrics panel allows you to graph a metric collected by Application Insights over time with optional filters and grouping. 像 Application Insights 中的其他内容一样,你可以将此图表添加到仪表板。Like everything else in Application Insights, you can add this chart to the dashboard. 这需要你先执行少量自定义操作。This does require you to do a little customization first.

  1. 在主屏幕中选择你的 Application Insights 资源。Select your Application Insights resource in the home screen.

  2. 选择“指标”。Select Metrics.

  3. 已创建空图表,系统会提示你添加指标。An empty chart has already been created, and you're prompted to add a metric. 向图表添加指标,并选择性地添加筛选器和分组。Add a metric to the chart and optionally add a filter and a grouping. 下面的示例显示了按成功分组的服务器请求数。The example below shows the number of server requests grouped by success. 这给出了成功和不成功请求的运行视图。This gives a running view of successful and unsuccessful requests.

    添加指标Add metric

  4. 在右侧选择“固定到仪表板”。Select Pin to dashboard on the right.

  5. 右上角将显示一条通知,指出你的磁贴已固定到仪表板上。In the top right, a notification will appear that your tile was pinned to your dashboard. 选择通知中的“已固定到仪表板”以返回到仪表板或使用仪表板选项卡。Select Pinned to dashboard in the notification to return to your dashboard or use the dashboard tab.

  6. 该磁贴现在已添加到仪表板。That tile is now added to your dashboard. 选择“编辑”以更改磁贴的位置。Select Edit to change the positioning of the tile. 选择磁贴并将其拖动至相应位置,然后选择“完成自定义”。Select and drag the tile into position and then select Done customizing.

添加日志查询Add Logs query

Azure Application Insights 日志提供了丰富的查询语言,使你能够分析 Application Insights 收集的所有数据。Azure Application Insights Logs provides a rich query language that allows you to analyze all of the data collected Application Insights. 与图表和其他视图一样,可以将日志查询的输出添加到仪表板。Just like charts and other views, you can add the output of a logs query to your dashboard.

  1. 在主屏幕中选择你的 Application Insights 资源。Select your Application Insights resource in the home screen.

  2. 选择左侧“监视”下的“日志”,打开“日志”选项卡。Select Logs on the left under "monitoring" to open the Logs tab.

  3. 键入以下查询,将返回前 10 个请求最多的页面及其请求次数:Type the following query, which returns the top 10 most requested pages and their request count:

    requests
    | summarize count() by name
    | sort by count_ desc
    | take 10
    
  4. 选择“运行”来验证查询的结果。Select Run to validate the results of the query.

  5. 选择“固定”图标Select the pin icon 图钉图标 然后选择仪表板的名称。and select the name of your dashboard.

  6. 在返回仪表板之前,请添加其他查询,但将其呈现为图表,以便你可以看到在仪表板中直观显示日志查询的不同方法。Before you go back to the dashboard, add another query, but render it as a chart so you see the different ways to visualize a logs query in a dashboard. 从以下查询开始,该查询总结了前 10 个最常出现异常的操作。Start with the following query that summarizes the top 10 operations with the most exceptions.

    exceptions
    | summarize count() by operation_Name
    | sort by count_ desc
    | take 10
    
  7. 选择“图表”,然后更改为“圆环图”以可视化输出。Select Chart and then change to a Doughnut to visualize the output.

    具有以上查询的圆环图Doughnut chart with above query

  8. 选择“固定”图标Select the pin icon 图钉图标 将图表固定到仪表板,然后返回到仪表板。on the top right to pin the chart to your dashboard and then return to your dashboard.

  9. 查询的结果现在以你选择的格式添加到仪表板。The results of the queries are now added to your dashboard in the format that you selected. 选择每一个并将其拖动至相应位置,然后选择“完成自定义”。Select and drag each into position and then select Done customizing.

  10. 选择每个标题上的铅笔图标Select the pencil icon 铅笔图标 来为其提供一个描述性标题。on each title to give them a descriptive title.

共享仪表板Share dashboard

  1. 在仪表板的顶部,选择“共享”以发布更改。At the top of the dashboard, select Share to publish your changes.
  2. 你可以定义具有仪表板访问权限的特定用户(可选)。You can optionally define specific users who should have access to the dashboard. 有关详细信息,请参阅使用 Azure 基于角色的访问控制共享 Azure 仪表板For more information, see Share Azure dashboards by using Azure role-based access control.
  3. 选择“发布”。Select Publish.

后续步骤Next steps

现在你已经学会了如何创建自定义仪表板,了解一下 Application Insights 文档的其余部分吧,包括案例研究。Now that you've learned how to create custom dashboards, have a look at the rest of the Application Insights documentation including a case study.