您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure Monitor 工作簿创建交互式报表Create interactive reports with Azure Monitor workbooks

工作簿可将 分析查询、Azure 指标和参数合并到丰富的交互式报表中。Workbooks combine text, Analytics queries, Azure Metrics, and parameters into rich interactive reports. 有权访问相同 Azure 资源的其他团队成员都可编辑工作簿。Workbooks are editable by any other team members who have access to the same Azure resources.

工作簿对以下情况非常有用,例如:Workbooks are helpful for scenarios like:

  • 如果事先不知道感兴趣的指标,请浏览应用的使用情况:用户数、保留率、转换率等。与其他使用情况分析工具不同,工作簿允许您组合多种类型的可视化和分析,使其适合这种自由格式浏览。Exploring the usage of your app when you don't know the metrics of interest in advance: numbers of users, retention rates, conversion rates, etc. Unlike other usage analytics tools, workbooks let you combine multiple kinds of visualizations and analyses, making them great for this kind of free-form exploration.
  • 通过显示主要交互的用户计数和其他指标,向团队成员说明新发布的功能的作用。Explaining to your team how a newly released feature is performing, by showing user counts for key interactions and other metrics.
  • 在应用中与团队的其他成员共享 A/B 实验的结果。Sharing the results of an A/B experiment in your app with other members of your team. 可以用文本解释实验的目标,然后展示用于评估实验的每个使用情况指标和 Analytics 查询,以及说明每个指标是否高于或低于目标的标注。You can explain the goals for the experiment with text, then show each usage metric and Analytics query used to evaluate the experiment, along with clear call-outs for whether each metric was above- or below-target.
  • 结合数据、文本说明和后续步骤讨论,报告故障对应用使用的影响,从而防止未来发生故障。Reporting the impact of an outage on the usage of your app, combining data, text explanation, and a discussion of next steps to prevent outages in the future.

从模板或已保存的工作簿开始Starting with a template or saved workbook

工作簿由可单独编辑的图表、表格、文本和输入控件构成的各部分组成。A workbook is made up of sections consisting of independently editable charts, tables, text, and input controls. 若要更好地了解工作簿,最好是打开一个。To better understand workbooks, it is best to open one up.

在应用的 Application Insights 体验中,选择左侧菜单中的“工作簿”。Select Workbooks from the left-hand menu from inside the Application Insights experience for your app.

导航到工作簿的屏幕截图

这将启动包含大量预先构建工作簿的工作簿库,以帮助你入门。This launches a workbook gallery with a number of prebuilt workbooks to help you get started.

工作簿库的屏幕截图

我们将从“默认模板”开始,位于“快速入门”标题下方。We'll start with the Default Template, which is located under the heading Quick start.

工作簿库的屏幕截图

编辑、重新排列、克隆和删除工作簿部分Editing, rearranging, cloning, and deleting workbook sections

工作簿具有两种模式:编辑模式和阅读模式。Workbooks have two modes: editing mode, and reading mode. 首次启动默认工作簿时,它将在编辑模式下打开。When the default workbook is first launched, it opens in editing mode. 这将显示工作簿的所有内容,其中包括以任何方式隐藏的任何步骤和参数。This shows all the content of the workbook, including any steps and parameters that are otherwise hidden. 阅读模式提供了简化的报表样式视图。Reading mode presents a simplified report style view. 这使你能够免去创建报表时所遇到的复杂性,同时仍保留相应的基础机制,即只需几次单击即可进行修改。This allows you to abstract away the complexity that went into creating a report while still having the underlying mechanics only a few clicks away when needed for modification.

Application Insights 工作簿部分编辑控件

  1. 完成编辑某个部分后,点击该部分左下角的“完成编辑”。When you're done editing a section, click Done Editing in the bottom left corner of the section.

  2. 创建某个部分的副本,请单击“克隆此部分”图标。To create a duplicate of a section, click the Clone this section icon. 创建副本是迭代查询的绝佳方式,不会丢失以前的迭代。Creating duplicate sections is a great to way to iterate on a query without losing previous iterations.

  3. 要上移工作簿中的某个部分,请单击“上移”或“下移”图标。To move up a section in a workbook, click the Move up or Move down icon.

  4. 若要永久删除某个部分,请单击“删除”图标。To remove a section permanently, click the Remove icon.

添加文本和 Markdown 部分Adding text and Markdown sections

为工作簿添加标题、说明和注释有助于叙述一组表和图表。Adding headings, explanations, and commentary to your workbooks helps turn a set of tables and charts into a narrative. 工作簿中的文本部分支持用于设置文本格式的 Markdown 语法,如标题、粗体、斜体和点符列表。Text sections in workbooks support the Markdown syntax for text formatting, like headings, bold, italics, and bulleted lists.

若要将文本部分添加到工作簿,使用工作簿底部或任何部分底部的“添加文本”按钮。To add a text section to your workbook, use the Add text button at the bottom of the workbook, or at the bottom of any section.

添加查询部分Adding query sections

工作簿中的查询部分

若要将查询部分添加到工作簿,使用工作簿底部或任何部分底部的“添加查询”按钮。To add query section to your workbook, use the Add query button at the bottom of the workbook, or at the bottom of any section.

查询部分非常灵活,可用于回答以下问题:Query sections are highly flexible and can be used to answer questions like:

  • 使用率下降的同一时段内,网站引发了多少异常?How many exceptions did your site throw during the same time period as a decline in usage?
  • 用户查看某个页面的页面加载时间分布是什么样的?What was the distribution of page load times for users viewing some page?
  • 有多少用户在网站上查看了某组页面,而没有查看其它组页面?How many users viewed some set of pages on your site, but not some other set of pages? 这有助于了解你是否有使用不同网站功能子集的用户群集(在 Kusto 查询语言中使用具有 kind=leftanti 修饰符的 join 运算符)。This can be useful to understand if you have clusters of users who use different subsets of your site's functionality (use the join operator with the kind=leftanti modifier in the Kusto query language).

此外,你还不仅限于通过工作簿启动的应用程序的上下文中进行查询。You also aren't only limited to querying from the context of the application you launched the workbook from. 只要你有权访问这些资源,就可跨多个受 Application Insights 监视的应用,以及 Log Analytics 工作区进行查询。You can query across multiple Application Insights monitored apps as well as Log Analytics workspaces as long as you have access permission to those resources.

若要从其他外部 Application Insights 资源中查询,请使用 app 标识符。To query from additional external Application Insights resources use the app identifier.

union app('app01').requests, app('app02').requests, requests
| summarize count() by bin(timestamp, 1h)

此查询结合来自三个不同应用程序的请求。This query is combining requests from three different applications. 名为 app01 的应用,名为 app02 的应用,以及本地 Application Insights 资源的请求。An app named app01, an app named app02, and the requests from the local Application Insights resource.

若要从外部 Log Analytics 工作区提取数据,请使用 workspace 标识符。To pull in data from an external Log Analytics workspace use the workspace identifier.

若要了解有关跨资源查询的详细信息,请参阅官方指南To learn more about cross-resource queries refer to the official guidance.

高级分析查询设置Advanced analytic query settings

每个部分都有自己的高级设置,可通过位于“添加参数”按钮右侧的设置图标 Application Insights 工作簿部分编辑控件访问。Each section has its own advanced settings, which are accessible via the settings icon Application Insights Workbooks section editing controls located to the right of the Add parameters button.

Application Insights 工作簿部分编辑控件

自定义宽度Custom width 此设置可将某项设置为任意大小,以便可将许多项容纳在单行中,使你更好地将图表和表格整理到丰富的交互式报表中。Set this to make an item an arbitrary size, so you can fit many items on a single line allowing you to better organize your charts and tables into rich interactive reports.
有条件可见Conditionally visible 使用此选项在阅读模式下根据参数隐藏步骤。Use this to hide steps based on a parameter when in reading mode.
导出参数Export a parameter 这允许网格或图表中的所选行能够导致后续步骤更改值或变得可见。This allows a selected row in the grid or chart to cause later steps to change values or become visible.
未进行编辑时显示查询Show query when not editing 这将在图表或表格上方显示查询,即便处于阅读模式也是如此。This displays the query above the chart or table even when in reading mode.
未进行编辑时显示“在分析中打开”按钮Show open in analytics button when not editing 这将向图表的右侧添加蓝色的“分析”图标,以允许单击访问。This adds the blue Analytics icon to the right-hand corner of the chart to allow one-click access.

大多数这些设置都相当直观,但若要了解导出参数,最好查看使用此功能的工作簿。Most of these settings are fairly intuitive, but to understand Export a parameter it is better to examine a workbook that makes use of this functionality.

其中一个预先构建的工作簿可提供有关活动用户的信息。One of the prebuilt workbooks provides information on Active Users.

工作簿的第一部分基于分析查询数据:The first section of the workbook is based on Analytic query data:

Application Insights 工作簿部分编辑控件

第个部分也基于分析查询数据,但在第一个表中选择某一行将交互更新图表的内容:The second section is also based on analytic query data, but selecting a row in the first table will interactively update the contents of the chart:

Application Insights 工作簿部分编辑控件

这可以通过使用在表格的分析查询中启用的高级设置“选择项目后,导出参数”实现。This is possible through use of the When an item is selected, export a parameter advanced settings that are enabled in the table's Analytics query.

Application Insights 工作簿部分编辑控件

然后,第二个分析查询将在选择某行时利用导出的值。The second analytics query then utilizes the exported values when a row is selected. 如果未选择行,则默认为表示总体值的行。If no row is selected, it defaults to the row representing the overall values.

let start = startofday(ago({TimeRange} + {Metric}));
union customEvents, pageViews
| where timestamp >= start
| where name in ({Activities}) or '*' in ({Activities}) or ('%' in ({Activities}) and itemType == 'pageView') or ('#' in ({Activities}) and itemType == 'customEvent')
{OtherFilters}
| where '{Filter}' == '' or '{Filter}' == '🔸 Overall' or {AnalyzeBy} == replace('🔹 ', '', '{Filter}')
| evaluate activity_engagement(user_Id, timestamp, start, now(), 1d, {Metric})
| where timestamp >= startofday(ago({TimeRange}))
| project timestamp, ["Active User"] = dcount_activities_outer
| render timechart 

添加指标部分Adding metrics sections

指标部分提供完全访问权限,以将 Azure Monitor 指标数据纳入交互式报表。Metrics sections give you full access to incorporate Azure Monitor metrics data into your interactive reports. 许多预构建的工作簿将同时包含分析查询数据和指标数据,使你能够在一处充分利用这两种功能。Many of the prebuilt workbooks will contain both analytic query data and metric data allowing you to take full advantage of the best of both features all in one place. 此外,还能够从任何有权访问的订阅中的资源中提取指标数据。You also have the ability to pull in metric data from resources in any of the subscriptions you have access to.

下例是关于被拉取到工作簿中以提供 CPU 性能的网格可视化效果的虚拟机数据:Here is an example of Virtual machine data being pulled into a workbook to provide a grid visualization of CPU performance:

Application Insights 工作簿部分编辑控件

添加参数部分Adding parameter sections

工作簿参数使你能够更改工作簿中的值,而无需手动编辑查询或文本部分。Workbook parameters allow you to change values in the workbook without having to manually edit the query or text sections. 这免除了对了解基础分析查询语言的需求,并极大地扩大了基于工作簿的报表的潜在受众范围。This removes the requirement of needing to understand the underlying analytics query language and greatly expands the potential audience of workbook-based reporting.

通过将参数名称放在大括号中(如 {parameterName}),以查询、文本或其他参数部分替换参数值。The values of parameters are replaced in query, text or other parameter sections by putting the name of the parameter in braces, like {parameterName}. 参数名称限于类似 JavaScript 标识符的规则,基本上是字母字符或下划线,后接字母数字字符或下划线。Parameter names are limited to similar rules as JavaScript identifiers, basically alphabetic characters or underscores, followed by alphanumeric characters or underscores. 例如,允许使用 a1,但不允许使用 1a。For example, a1 is allowed, but 1a is not allowed.

参数是线性的,从工作簿的顶部开始并向下转到后续步骤。Parameters are linear, starting from the top of a workbook and flowing down to later steps. 工作簿中稍后声明的参数可以替代前面声明的参数。Parameters declared later in a workbook can override those that were declared further up. 此外,这还允许使用查询的参数访问前面定义的参数值。This also lets parameters that use queries to access the values from parameters defined further up. 在参数步骤本身中,参数也是线性的,从左到右,右侧的参数可以依赖以前在该步骤中声明的参数。Within a parameter's step itself, parameters are also linear, left to right, where parameters to the right can depend on a parameter declared earlier in that same step.

当前支持四种不同类型的参数:There are four different types of parameters which are currently supported:

TextText 用户将编辑文本框,并可以选择提供一个查询用于填充默认值。the user will edit a text box, and you can optionally supply a query to fill in the default value.
下拉列表Drop down 用户将从一组值中选择。The user will choose from a set of values.
时间范围选取器Time range picker 用户将从一组预定义的时间范围值中选择,或者从自定义时间范围中选择。The user will choose from a predefined set of time range values, or pick from a custom time range.
资源选取器Resource picker 用户将从为工作簿所选资源中选择。The user will choose from the resources selected for the workbook.

使用文本参数Using a text parameter

用户在文本框中输入的值将直接在查询中替换,不带任何转义或引号。The value a user types in the textbox is replaced directly in the query, with no escaping or quoting. 如果所需值为字符串,则查询应该在参数周围采用引号(如 '{parameter}')。If the value you need is a string, the query should have quotes around the parameter (like '{parameter}').

这样,文本框中的值可在任意位置使用。This allows the value in a text box to be used anywhere. 它可以是表名、列名、函数名、运算符等等。It can be a table name, column name, function name, operator, etc.

文本参数类型包含“从分析查询获取默认值”设置,使工作簿作者能够使用查询填充该文本框的默认值。The text parameter type has a setting Get default value from analytics query, which allows the workbook author to use a query to populate the default value for that textbox.

使用分析查询中的默认值时,仅第一行的第一个值(行 0,列 0)用作默认值。When using the default value from an analytics query, only the first value of the first row (row 0, column 0) is used as the default value. 因此建议限制查询,以仅返回一行和一列。Therefore it is recommended to limit your query to return just one row and one column. 忽略由查询返回的其他任何数据。Any other data returned by the query is ignored.

查询返回的任何值都将被直接替换,不带任何转义或引号。Whatever value the query returns will be replaced directly with no escaping or quoting. 如果查询不返回行,该参数的结果为空字符串(如果参数不是必需的)或未定义(如果参数是必需的)。If the query returns no rows, the result of the parameter is either an empty string (if the parameter is not required) or undefined (if the parameter is required).

使用下拉列表Using a dropdown

下拉列表参数类型可让你创建一个下拉列表控件,支持选择一个或多个值。The dropdown parameter type lets you create a dropdown control, allowing the selection of one or many values.

下拉列表由分析查询进行填充。The dropdown is populated by an analytics query. 如果查询返回一列,则该列中的值同时为下拉列表控件中的值和标签。If the query returns one column, the values in that column are both the value and the label in the dropdown control. 如果查询返回两列,第一列为值,第二列为下拉列表中显示的标签。If the query returns two columns, the first column is the value, and the second column is the label shown in the dropdown. 如果查询返回三列,则第三列用于指示该下拉列表中的默认选择。If the query returns three columns, the 3rd column is used to indicate the default selection in that dropdown. 此列可以是任何类型,但最简单的是使用布尔值或数值类型,其中 0 表示 false,1 表示 true。This column can be any type, but the simplest is to use bool or numeric types, where 0 is false, and 1 is true.

如果列为字符串类型,null/空字符串被视为 false,而任何其他值被视为 true。If the column is a string type, null/empty string is considered false, and any other value is considered true. 对于单项选择下拉列表,值为 true 的第一个值用作默认选择。For single selection dropdowns, the first value with a true value is used as the default selection. 对于多项选择下拉列表,值为 true 的所有值用作默认选择集。For multiple selection dropdowns, all values with a true value are used as the default selected set. 下拉列表中的项以查询返回行的任何顺序显示。The items in the dropdown are shown in whatever order the query returned rows.

让我们看看活动用户报表中提供的参数。Let's look at the parameters present in the Active Users report. 单击“时间范围”旁边的编辑符号。Click the edit symbol next to TimeRange.

Application Insights 工作簿部分编辑控件

这将启动“编辑参数”菜单项:This will launch the Edit Parameter menu item:

Application Insights 工作簿部分编辑控件

查询使用称为数据表的分析查询语言功能,使用户能够生成任意表,表中全是无中生有的内容。The query uses a feature of the analytics query language called a datatable that lets you generate an arbitrary table, full of content, out of thin air! 例如,以下分析查询:For example, the following analytics query:

datatable( column1:string, column2:string )
[
 "row 1 column 1", "row 1 column 2",
"row 2 column 1", "row 2 column 2"
]

生成结果:Generates the result:

Application Insights 工作簿部分编辑控件

更适用的示例是使用下拉列表按名称从一组国家/地区中进行选择:A more applicable example is using a dropdown to pick from a set of countries/regions by name:

customEvents
| where timestamp >= ago(14d)
| summarize count() by client_CountryOrRegion
| top 100 by count_
| project  client_CountryOrRegion 
| order by client_CountryOrRegion asc

该查询将显示如下所示的结果:The query will display results as follows:

国家/地区下拉列表

下拉列表是极其强大的工具,可用于自定义和创建交互式报表。Dropdowns are incredibly powerful tools for customizing and creating interactive reports.

时间范围参数Time range parameters

尽管可以通过下拉列表参数类型制作自己的自定义时间范围参数,但如果不需要相同程度的灵活性,还可使用现成的时间范围参数类型。While you can make your own custom time range parameter via the dropdown parameter type, you can also use the out-of-box time range parameter type if you don't need the same degree of flexibility.

时间范围参数类型包含 15 个默认范围,从 5 分钟到 90 天不等。Time range parameter types have 15 default ranges that go from five minutes to the last 90 days. 此外,还可以通过一个选项,允许自定义时间范围选择,使报表操作员能够选择明确的开始和停止时间范围值。There is also an option to allow custom time range selection, which allows the operator of the report to choose explicit start and stop values for the time range.

资源选取器Resource picker

资源选取器参数类型使你能够将报表类型范围限定到特定资源类型。The resource picker parameter type gives you the ability to scope your report to certain types of resources. Failure Insights 工作簿就是利用资源选取器类型的一个预先构建工作簿示例。An example of prebuilt workbook that leverages the resource picker type is the Failure Insights workbook.

国家/地区下拉列表

保存并与团队共享工作簿Saving and sharing workbooks with your team

无论是在私有的“我的报表”部分中,还是在有权访问 Application Insights 资源的每个人均可访问的“共享报表”部分中,工作簿都保存在 Application Insights 内。Workbooks are saved within an Application Insights resource, either in the My Reports section that's private to you or in the Shared Reports section that's accessible to everyone with access to the Application Insights resource. 若要查看资源中的所有工作簿,请单击操作栏中的“打开”按钮。To view all the workbooks in the resource, click the Open button in the action bar.

共享目前在“我的报表”中的工作簿:To share a workbook that's currently in My Reports:

  1. 在操作栏中,单击“打开”Click Open in the action bar
  2. 单击要共享的工作簿旁的“...”按钮Click the "..." button beside the workbook you want to share
  3. 单击“移到共享报表”。Click Move to Shared Reports.

若要通过链接或电子邮件共享工作簿,请单击操作栏中的“共享”。To share a workbook with a link or via email, click Share in the action bar. 请记住,链接的收件人需要在 Azure 门户中访问此资源才能查看该工作簿。Keep in mind that recipients of the link need access to this resource in the Azure portal to view the workbook. 若要进行编辑,收件人至少需要资源的参与者权限。To make edits, recipients need at least Contributor permissions for the resource.

将工作簿的链接固定到 Azure 仪表板:To pin a link to a workbook to an Azure Dashboard:

  1. 在操作栏中,单击“打开”Click Open in the action bar
  2. 单击需固定的工作簿旁的“...”按钮Click the "..." button beside the workbook you want to pin
  3. 单击“固定到仪表板”。Click Pin to dashboard.

参与创建工作簿模板Contributing workbook templates

你是否创建了令人惊叹的工作簿模板,并且想要与社区共享?Have you created an awesome workbook template and want to share it with the community? 若要了解详细信息,请访问 GitHub 存储库To learn more, visit our GitHub repo.

后续步骤Next steps