在 Visual Studio 中分析趋势Analyzing Trends in Visual Studio

Application Insights 趋势工具以可视化方式呈现 Web 应用程序在各时间段的重要遥测事件变化,帮助快速识别问题和异常。The Application Insights Trends tool visualizes how your web application's important telemetry events change over time, helping you quickly identify problems and anomalies. “趋势”提供更详细诊断信息的链接,可帮助改进应用程序性能、跟踪异常的原因,以及从自定义事件中找到见解。By linking you to more detailed diagnostic information, Trends can help you improve your app's performance, track down the causes of exceptions, and uncover insights from your custom events.

示例趋势窗口

为 Application Insights 配置 Web 应用Configure your web app for Application Insights

如果没有完成此操作,请为 Application Insights 配置 Web 应用If you haven't done this already, configure your web app for Application Insights. 这样即可将遥测数据发送到 Application Insights 门户。This allows it to send telemetry to the Application Insights portal. 趋势工具从该处读取遥测数据。The Trends tool reads the telemetry from there.

Application Insights 趋势在 Visual Studio 2015 Update 3 及更高版本中提供。Application Insights Trends is available in Visual Studio 2015 Update 3 and later.

若要打开“Application Insights 趋势”窗口,请执行以下操作:To open the Application Insights Trends window:

  • 通过 Application Insights 工具栏按钮选择“浏览遥测趋势”,或者From the Application Insights toolbar button, choose Explore Telemetry Trends, or
  • 在项目上下文菜单中选择“Application Insights”>“浏览遥测趋势”,或者From the project context menu, choose Application Insights > Explore Telemetry Trends, or
  • 在 Visual Studio 菜单栏中,选择“视图”>“其他窗口”>“Application Insights 趋势”。From the Visual Studio menu bar, choose View > Other Windows > Application Insights Trends.

此时会出现选择资源的提示。You may see a prompt to select a resource. 单击“选择资源”,使用 Azure 订阅登录,并从列表中选择要分析其遥测趋势的 Application Insights 资源。Click Select a resource, sign in with an Azure subscription, then choose an Application Insights resource from the list for which you'd like to analyze telemetry trends.

选择趋势分析Choose a trend analysis

常用趋势分析类型的菜单

首先选择五种通用趋势分析中的一种,其中的每一种都可分析过去 24 小时内的数据:Get started by choosing from one of five common trend analyses, each analyzing data from the last 24 hours:

  • 调查服务器请求的性能问题 - 对服务发出的请求,按响应时间分组Investigate performance issues with your server requests - Requests made to your service, grouped by response times
  • 分析服务器请求中的错误 - 对服务发出的请求,按 HTTP 响应代码分组Analyze errors in your server requests - Requests made to your service, grouped by HTTP response code
  • 检查应用程序中的异常 - 服务中的异常,按异常类型分组Examine the exceptions in your application - Exceptions from your service, grouped by exception type
  • 检查应用程序依赖项的性能 - 用户服务调用的服务,按响应时间分组Check the performance of your application's dependencies - Services called by your service, grouped by response times
  • 检查自定义事件 - 为服务设置的自定义事件,按事件类型分组。Inspect your custom events - Custom events you've set up for your service, grouped by event type.

稍后可从“趋势”窗口左上角的“查看常见的遥测分析类型”按钮获取这些预先构建的分析。These pre-built analyses are available later from the View common types of telemetry analysis button in the upper-left corner of the Trends window.

Application Insights 趋势基于应用的遥测数据创建时序视觉效果。Application Insights Trends creates a time series visualization from your app's telemetry. 每个时序视觉效果显示某个时间范围内一种类型的遥测(按该遥测的某个属性分组)。Each time series visualization displays one type of telemetry, grouped by one property of that telemetry, over some time range. 例如,可以查看过去 24 小时内的服务器请求(按来源国家/地区分组)。For example, you might want to view server requests, grouped by the country/region from which they originated, over the last 24 hours. 在本示例中,视觉效果上的每个气泡代表一小时内某个国家/地区的服务器请求计数。In this example, each bubble on the visualization would represent a count of the server requests for some country/region during one hour.

使用窗口顶部的控件可调整要查看的遥测类型。Use the controls at the top of the window to adjust what types of telemetry you view. 首先,选择感兴趣的遥测类型:First, choose the telemetry types in which you're interested:

  • 遥测类型 - 服务器请求、异常、依赖项或自定义事件Telemetry Type - Server requests, exceptions, dependencies, or custom events
  • 时间范围 - 从过去 30 分钟到过去 3 天的任何时间段Time Range - Anywhere from the last 30 minutes to the last 3 days
  • 分组依据 - 异常类型、问题 ID、国家/地区,等等。Group By - Exception type, problem ID, country/region, and more.

然后,单击“分析遥测”以运行查询。Then, click Analyze Telemetry to run the query.

若要在视觉效果中的气泡之间导航:To navigate between bubbles in the visualization:

  • 通过单击选择气泡,该气泡将更新窗口底部的筛选器,并且只汇总特定时间段内发生的事件Click to select a bubble, which updates the filters at the bottom of the window, summarizing just the events that occurred during a specific time period
  • 双击气泡可以导航到“搜索”工具,查看在该时间段内发生的所有遥测事件Double-click a bubble to navigate to the Search tool and see all of the individual telemetry events that occurred during that time period
  • 在按住 Ctrl 键的同时单击气泡可在视觉效果中取消选择该气泡。Ctrl-click a bubble to de-select it in the visualization.

提示

“趋势”和“搜索”工具配合工作,帮助在数千个遥测事件中找到服务中问题的原因。The Trends and Search tools work together to help you pinpoint the causes of issues in your service among thousands of telemetry events. 例如,如果客户在某天下午告知应用的响应速度不快,便可以从“趋势”着手。For example, if one afternoon your customers notice your app is being less responsive, start with Trends. 分析过去若干小时内对服务发出的请求(按响应时间分组)。Analyze requests made to your service over the past several hours, grouped by response time. 检查是否速度缓慢的请求数量是否超乎寻常。See if there's an unusually large cluster of slow requests. 然后双击该气泡以转到“搜索”工具,该工具已筛选出这些请求事件。Then double click that bubble to go to the Search tool, filtered to those request events. 在“搜索”中,可以浏览这些请求的内容并导航到相关代码来解决问题。From Search, you can explore the contents of those requests and navigate to the code involved to resolve the issue.

筛选器Filter

使用窗口底部的筛选控件发现更明确的趋势。Discover more specific trends with the filter controls at the bottom of the window. 若要应用某个筛选器,请单击其名称。To apply a filter, click on its name. 可以快速切换不同的筛选器,发现可能隐藏在遥测特定维度中的趋势。You can quickly switch between different filters to discover trends that may be hiding in a particular dimension of your telemetry. 如果在某个维度(例如异常类型)中应用一个筛选器,其他维度中的筛选器即使灰显,也仍可以点击。若要取消应用某个筛选器,请再次单击它。If you apply a filter in one dimension, like Exception Type, filters in other dimensions remain clickable even though they appear grayed-out. To un-apply a filter, click it again. 在按住 Ctrl 的同时单击可以选择同一维度中的多个筛选器。Ctrl-click to select multiple filters in the same dimension.

趋势筛选器

要应用多个筛选器怎么办?What if you want to apply multiple filters?

  1. 应用第一个筛选器。Apply the first filter.
  2. 单击第一个筛选器的维度名称旁边的“应用选定的筛选器并再次查询”按钮。Click the Apply selected filters and query again button by the name of the dimension of your first filter. 这只会针对匹配第一个筛选器的事件重新查询遥测。This will re-query your telemetry for only events that match the first filter.
  3. 应用第二个筛选器。Apply a second filter.
  4. 重复上述过程,在遥测的特定子集中查找趋势。Repeat the process to find trends in specific subsets of your telemetry. 例如,名为“GET Home/Index”来自德国收到了 500 响应代码的服务器请求。For example, server requests named "GET Home/Index" and that came from Germany and that received a 500 response code.

若要取消应用上述筛选器之一,请单击维度对应的“删除选定的筛选器并再次查询”按钮。To un-apply one of these filters, click the Remove selected filters and query again button for the dimension.

多个筛选器

查找异常Find anomalies

“趋势”工具突出显示异常事件的气泡,与同一时序中的其他气泡相对比。The Trends tool can highlight bubbles of events that are anomalous compared to other bubbles in the same time series. 在“视图类型”下拉列表中,选择“时间存储桶中的计数(突出显示异常)”或“时间存储桶中的百分比(突出显示异常)” 。In the View Type dropdown, choose Counts in time bucket (highlight anomalies) or Percentages in time bucket (highlight anomalies). 红色气泡表示异常。Red bubbles are anomalous. 异常定义为计数/百分比超过 2.1 乘以在过去两个时间周期(如果正在查看过去 24 小时的数据,则为 48 小时)内发生的计数/百分比的标准偏差的气泡。Anomalies are defined as bubbles with counts/percentages exceeding 2.1 times the standard deviation of the counts/percentages that occurred in the past two time periods (48 hours if you're viewing the last 24 hours, etc.).

彩色圆点表示异常

提示

在小型气泡的时序中查找可能看起来大小相似的离群值时,突出显示异常特别有用。Highlighting anomalies is especially helpful for finding outliers in time series of small bubbles that may otherwise look similarly sized.

后续步骤Next steps

在 Visual Studio 中使用 Application InsightsWorking with Application Insights in Visual Studio
搜索遥测、查看 CodeLens 中的数据以及配置 Application Insights。Search telemetry, see data in CodeLens, and configure Application Insights. 一切尽在 Visual Studio 中。All within Visual Studio.
右键单击项目,并依次选择“Application Insights”、“搜索”
添加更多数据Add more data
监视使用情况、可用性、依赖项、异常。Monitor usage, availability, dependencies, exceptions. 集成来自记录框架的跟踪。Integrate traces from logging frameworks. 编写自定义遥测。Write custom telemetry.
Visual Studio
使用 Application Insights 门户Working with the Application Insights portal
仪表板、功能强大的诊断和分析工具、警报、应用程序的实时依赖项映射和遥测导出。Dashboards, powerful diagnostic and analytic tools, alerts, a live dependency map of your application, and telemetry export.
Visual Studio