基于 Application Insights 日志的指标Application Insights log-based metrics

使用基于 Application Insights 日志的指标可以分析受监视应用的运行状况、创建功能强大的仪表板,以及配置警报。Application Insights log-based metrics let you analyze the health of your monitored apps, create powerful dashboards, and configure alerts. 有两种类型的指标:There are two kinds of metrics:

由于标准指标在收集期间会预先聚合,因此它们在查询时具有更好的性能。 Since standard metrics are pre-aggregated during collection, they have better performance at query time. 因此它们更适合在仪表板和实时警报中显示。This makes them a better choice for dashboarding and in real-time alerting. 基于日志的指标具有更多的维度,因此,它们特别适合用于数据分析和即席诊断。 The log-based metrics have more dimensions, which makes them the superior option for data analysis and ad-hoc diagnostics. 指标资源管理器中使用命名空间选择器可以在基于日志的指标与标准指标之间切换。Use the namespace selector to switch between log-based and standard metrics in metrics explorer.

本文中的查询的解释和用法Interpret and use queries from this article

本文列出了指标以及支持的聚合与维度。This article lists metrics with supported aggregations and dimensions. 基于日志的指标的详细信息包括底层 Kusto 查询语句。The details about log-based metrics include the underlying Kusto query statements. 为方便起见,每个查询对时间粒度、图表类型使用默认值,有时还会拆分维度,这简化了查询在 Log Analytics 中的使用,而无需进行任何修改。For convenience, each query uses defaults for time granularity, chart type, and sometimes splitting dimension which simplifies using the query in Log Analytics without any need for modification.

指标资源管理器中绘制同一指标的图表时,不会使用默认值 - 查询会根据图表设置动态调整:When you plot the same metric in metrics explorer, there are no defaults - the query is dynamically adjusted based on your chart settings:

  • 所选的“时间范围”将转换为额外的 where timestamp ... 子句,以便仅选取所选时间范围内的事件。The selected Time range is translated into an additional where timestamp... clause to only pick the events from selected time range. 例如,对于显示最近 24 小时数据的图表,查询将包含 | where timestamp > ago(24 h)For example, a chart showing data for the most recent 24 hours, the query includes | where timestamp > ago(24 h).

  • 所选的“时间粒度”将放入最终的 summarize ... by bin(timestamp, [time grain]) 子句。The selected Time granularity is put into the final summarize ... by bin(timestamp, [time grain]) clause.

  • 任何所选“筛选器”维度将转换为额外的 where 子句。Any selected Filter dimensions are translated into additional where clauses.

  • 所选的“拆分图表”维度将转换为额外的 summarize 属性。 The selected Split chart dimension is translated into an extra summarize property. 例如,如果你按位置拆分图表,并使用 5 分钟时间粒度绘制图表,则 summarize 子句将由 ... by bin(timestamp, 5 m), location 汇总。For example, if you split your chart by location, and plot using a 5-minute time granularity, the summarize clause is summarized ... by bin(timestamp, 5 m), location.

备注

如果你不熟悉 Kusto 查询语言,请先复制 Kusto 语句并将其粘贴到 Log Analytics 查询窗格,而无需进行任何修改。If you're new to the Kusto query language, you start by copying and pasting Kusto statements into the Log Analytics query pane without making any modifications. 单击“运行”查看基本图表。 Click Run to see basic chart. 对查询语言的语法有一定的了解后,可以开始进行少量的修改,并查看更改造成的影响。As you begin to understand the syntax of query language, you can start making small modifications and see the impact of your change. 探索自己的数据是开始实现 Log AnalyticsAzure Monitor 的全部功能的好办法。Exploring your own data is a great way to start realizing the full power of Log Analytics and Azure Monitor.

可用性指标Availability metrics

参考“可用性”类别中的指标可以了解在世界各地预测到的 Web 应用程序运行状况。Metrics in the Availability category enable you to see the health of your web application as observed from points around the world. 配置可用性测试,以开始使用此类别中的任何指标。Configure the availability tests to start using any metrics from this category.

可用性 (availabilityResults/availabilityPercentage)Availability (availabilityResults/availabilityPercentage)

“可用性”指标显示未检测到任何问题的 Web 测试运行的百分比。 The Availability metric shows the percentage of the web test runs that didn't detect any issues. 可能的最小值为 0,表示所有 Web 测试运行均失败。The lowest possible value is 0, which indicates that all of the web test runs have failed. 值 100 表示所有 Web 测试运行都符合验证条件。The value of 100 means that all of the web test runs passed the validation criteria.

度量单位Unit of measure 支持的聚合Supported aggregations 支持的维度Supported dimensions
百分比Percentage 平均值Average 运行位置、测试名称Run location, Test name
availabilityResults 
| summarize sum(todouble(success == 1) * 100) / count() by bin(timestamp, 5m), location
| render timechart

可用性测试持续时间 (availabilityResults/duration)Availability test duration (availabilityResults/duration)

“可用性测试持续时间”指标显示运行 Web 测试所花费的时间。 The Availability test duration metric shows how much time it took for the web test to run. 对于多步骤 Web 测试,该指标反映所有步骤的总执行时间。For the multi-step web tests, the metric reflects the total execution time of all steps.

度量单位Unit of measure 支持的聚合Supported aggregations 支持的维度Supported dimensions
毫秒Milliseconds Average、Min、MaxAverage, Min, Max 运行位置、测试名称、测试结果Run location, Test name, Test result
availabilityResults
| where notempty(duration)
| extend availabilityResult_duration = iif(itemType == 'availabilityResult', duration, todouble(''))
| summarize sum(availabilityResult_duration)/sum(itemCount) by bin(timestamp, 5m), location
| render timechart

可用性测试 (availabilityResults/count)Availability tests (availabilityResults/count)

“可用性测试”指标反映 Azure Monitor 执行的 Web 测试运行计数。 The Availability tests metric reflects the count of the web tests runs by Azure Monitor.

度量单位Unit of measure 支持的聚合Supported aggregations 支持的维度Supported dimensions
计数Count 计数Count 运行位置、测试名称、测试结果Run location, Test name, Test result
availabilityResults
| summarize sum(itemCount) by bin(timestamp, 5m)
| render timechart

浏览器指标Browser metrics

浏览器指标由 Application Insights JavaScript SDK 从实际的最终用户浏览器收集。Browser metrics are collected by the Application Insights JavaScript SDK from real end-user browsers. 它们提供 Web 应用用户体验的深入见解。They provide great insights into your users' experience with your web app. 通常不会对浏览器指标采样,这意味着,在用量数字方面,与服务器端指标相比,它们提供的精度更高,而后者的采样可能会导致结果有偏差。Browser metrics are typically not sampled, which means that they provide higher precision of the usage numbers compared to server-side metrics which might be skewed by sampling.

备注

若要收集浏览器指标,必须使用 Application Insights JavaScript SDK 来检测应用程序。To collect browser metrics, your application must be instrumented with the Application Insights JavaScript SDK.

浏览器页面加载时间 (browserTimings/totalDuration)Browser page load time (browserTimings/totalDuration)

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions
毫秒Milliseconds Average、Min、MaxAverage, Min, Max None
browserTimings
| where notempty(totalDuration)
| extend _sum = totalDuration
| extend _count = itemCount
| extend _sum = _sum * _count
| summarize sum(_sum) / sum(_count) by bin(timestamp, 5m)
| render timechart

客户端处理时间 (browserTiming/processingDuration)Client processing time (browserTiming/processingDuration)

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions
毫秒Milliseconds Average、Min、MaxAverage, Min, Max None
browserTimings
| where notempty(processingDuration)
| extend _sum = processingDuration
| extend _count = itemCount
| extend _sum = _sum * _count
| summarize sum(_sum)/sum(_count) by bin(timestamp, 5m)
| render timechart

页面加载网络连接时间 (browserTimings/networkDuration)Page load network connect time (browserTimings/networkDuration)

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions
毫秒Milliseconds Average、Min、MaxAverage, Min, Max None
browserTimings
| where notempty(networkDuration)
| extend _sum = networkDuration
| extend _count = itemCount
| extend _sum = _sum * _count
| summarize sum(_sum) / sum(_count) by bin(timestamp, 5m)
| render timechart

接收响应时间 (browserTimings/receiveDuration)Receiving response time (browserTimings/receiveDuration)

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions
毫秒Milliseconds Average、Min、MaxAverage, Min, Max None
browserTimings
| where notempty(receiveDuration)
| extend _sum = receiveDuration
| extend _count = itemCount
| extend _sum = _sum * _count
| summarize sum(_sum) / sum(_count) by bin(timestamp, 5m)
| render timechart

发送请求时间 (browserTimings/sendDuration)Send request time (browserTimings/sendDuration)

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions
毫秒Milliseconds Average、Min、MaxAverage, Min, Max None
browserTimings
| where notempty(sendDuration)
| extend _sum = sendDuration
| extend _count = itemCount
| extend _sum = _sum * _count
| summarize sum(_sum) / sum(_count) by bin(timestamp, 5m)
| render timechart

失败指标Failure metrics

“失败”中的指标显示处理请求、依赖项调用的问题,以及引发的异常。 The metrics in Failures show problems with processing requests, dependency calls, and thrown exceptions.

浏览器异常数 (exceptions/browser)Browser exceptions (exceptions/browser)

此指标反映浏览器中运行的应用程序代码引发的异常数。This metric reflects the number of thrown exceptions from your application code running in browser. 该指标仅包含使用 trackException() Application Insights API 调用跟踪的异常。Only exceptions that are tracked with a trackException() Application Insights API call are included in the metric.

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions 注释Notes
计数Count 计数Count None 基于日志的版本使用 Sum 聚合Log-based version uses Sum aggregation
exceptions
| where notempty(client_Browser)
| summarize sum(itemCount) by bin(timestamp, 5m)
| render barchart

依赖项调用失败数 (dependencies/failed)Dependency call failures (dependencies/failed)

失败的依赖项调用数。The number of failed dependency calls.

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions 注释Notes
计数Count 计数Count None 基于日志的版本使用 Sum 聚合Log-based version uses Sum aggregation
dependencies
| where success == 'False'
| summarize sum(itemCount) by bin(timestamp, 5m)
| render barchart

异常数 (exceptions/count)Exceptions (exceptions/count)

每当你将异常记录到 Application Insights 时,都会调用 SDK 的 trackException() 方法Each time when you log an exception to Application Insights, there is a call to the trackException() method of the SDK. “异常数”指标显示记录的异常数。The Exceptions metric shows the number of logged exceptions.

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions 注释Notes
计数Count 计数Count 云角色名称、云角色实例、设备类型Cloud role name, Cloud role instance, Device type 基于日志的版本使用 Sum 聚合Log-based version uses Sum aggregation
exceptions
| summarize sum(itemCount) by bin(timestamp, 5m)
| render barchart

失败的请求数 (请求/失败)Failed requests (requests/failed)

标记为失败的受跟踪服务器请求计数。 The count of tracked server requests that were marked as failed. 默认情况下,Application Insights SDK 会自动将返回 HTTP 响应代码 5xx 或 4xx 的每个服务器请求标记为失败的请求。By default, the Application Insights SDK automatically marks each server request that returned HTTP response code 5xx or 4xx as a failed request. 可以通过在自定义遥测初始化表达式中修改请求遥测项的 success 属性来自定义此逻辑。You can customize this logic by modifying success property of request telemetry item in a custom telemetry initializer.

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions 注释Notes
计数Count 计数Count 云角色实例、云角色名称、实际或综合流量、请求性能、响应代码Cloud role instance, Cloud role name, Real or synthetic traffic, Request performance, Response code 基于日志的版本使用 Sum 聚合Log-based version uses Sum aggregation
requests
| where success == 'False'
| summarize sum(itemCount) by bin(timestamp, 5m)
| render barchart

服务器异常数 (exceptions/server)Server exceptions (exceptions/server)

此指标显示服务器异常数。This metric shows the number of server exceptions.

度量单位Unit of measure 支持的聚合Supported aggregations 预先聚合的维度Pre-aggregated dimensions 注释Notes
计数Count 计数Count 云角色名称、云角色实例Cloud role name, Cloud role instance 基于日志的版本使用 Sum 聚合Log-based version uses Sum aggregation
exceptions
| where isempty(client_Browser)
| summarize sum(itemCount) by bin(timestamp, 5m)
| render barchart

性能计数器Performance counters

使用“性能计数器”类别中的指标可以访问 Application Insights 收集的系统性能计数器Use metrics in the Performance counters category to access system performance counters collected by Application Insights.

可用内存 (performanceCounters/availableMemory)Available memory (performanceCounters/availableMemory)

performanceCounters
| where ((category == "Memory" and counter == "Available Bytes") or name == "availableMemory")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

异常率 (performanceCounters/exceptionRate)Exception rate (performanceCounters/exceptionRate)

performanceCounters
| where ((category == ".NET CLR Exceptions" and counter == "# of Exceps Thrown / sec") or name == "exceptionRate")
| extend performanceCounter_value = iif(itemType == 'performanceCounter',value,todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

HTTP 请求执行时间 (performanceCounters/requestExecutionTime)HTTP request execution time (performanceCounters/requestExecutionTime)

performanceCounters
| where ((category == "ASP.NET Applications" and counter == "Request Execution Time") or name == "requestExecutionTime")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

HTTP 请求速率 (performanceCounters/requestsPerSecond)HTTP request rate (performanceCounters/requestsPerSecond)

performanceCounters
| where ((category == "ASP.NET Applications" and counter == "Requests/Sec") or name == "requestsPerSecond")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

应用程序队列中的 HTTP 请求数 (performanceCounters/requestsInQueue)HTTP requests in application queue (performanceCounters/requestsInQueue)

performanceCounters
| where ((category == "ASP.NET Applications" and counter == "Requests In Application Queue") or name == "requestsInQueue")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

进程 CPU (performanceCounters/processCpuPercentage)Process CPU (performanceCounters/processCpuPercentage)

该指标显示托管受监视应用的进程消耗的处理器总容量。The metric shows how much of the total processor capacity is consumed by the process that is hosting your monitored app.

度量单位Unit of measure 支持的聚合Supported aggregations 支持的维度Supported dimensions
百分比Percentage Average、Min、MaxAverage, Min, Max 云角色实例Cloud role instance
performanceCounters
| where ((category == "Process" and counter == "% Processor Time Normalized") or name == "processCpuPercentage")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

进程 IO 速率 (performanceCounters/processIOBytesPerSecond)Process IO rate (performanceCounters/processIOBytesPerSecond)

度量单位Unit of measure 支持的聚合Supported aggregations 支持的维度Supported dimensions
每秒字节数Bytes per second Average、Min、MaxAverage, Min, Max 云角色实例Cloud role instance
performanceCounters
| where ((category == "Process" and counter == "IO Data Bytes/sec") or name == "processIOBytesPerSecond")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

进程专用字节数 (performanceCounters/processPrivateBytes)Process private bytes (performanceCounters/processPrivateBytes)

受监视进程为其数据分配的非共享内存量。Amount of non-shared memory that the monitored process allocated for its data.

度量单位Unit of measure 支持的聚合Supported aggregations 支持的维度Supported dimensions
字节Bytes Average、Min、MaxAverage, Min, Max 云角色实例Cloud role instance
performanceCounters
| where ((category == "Process" and counter == "Private Bytes") or name == "processPrivateBytes")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

处理器时间 (performanceCounters/processorCpuPercentage)Processor time (performanceCounters/processorCpuPercentage)

受监视服务器实例上运行的所有进程的 CPU 消耗量。 CPU consumption by all processes running on the monitored server instance.

度量单位Unit of measure 支持的聚合Supported aggregations 支持的维度Supported dimensions
百分比Percentage Average、Min、MaxAverage, Min, Max 云角色实例Cloud role instance

备注

处理器时间指标不适用于 Azure 应用服务中托管的应用程序。The processor time metric is not available for the applications hosted in Azure App Services. 使用 进程 CPU 指标可以跟踪应用服务中托管的 Web 应用程序的 CPU 利用率。Use the Process CPU metric to track CPU utilization of the web applications hosted in App Services.

performanceCounters
| where ((category == "Processor" and counter == "% Processor Time") or name == "processorCpuPercentage")
| extend performanceCounter_value = iif(itemType == "performanceCounter", value, todouble(''))
| summarize sum(performanceCounter_value) / count() by bin(timestamp, 1m)
| render timechart

服务器指标Server metrics

依赖项调用数 (dependencies/count)Dependency calls (dependencies/count)

此指标与依赖项调用数相关。This metric is in relation to the number of dependency calls.

dependencies
| summarize sum(itemCount) by bin(timestamp, 5m)
| render barchart

依赖项持续时间 (dependencies/duration)Dependency duration (dependencies/duration)

此指标是指依赖项调用的持续时间。This metric refers to duration of dependency calls.

dependencies
| where notempty(duration)
| extend dependency_duration = iif(itemType == 'dependency',duration,todouble(''))
| extend _sum = dependency_duration
| extend _count = itemCount
| extend _sum = _sum*_count
| summarize sum(_sum)/sum(_count) by bin(timestamp, 1m)
| render timechart

服务器请求数 (requests/count)Server requests (requests/count)

此指标反映 Web 应用程序收到的传入服务器请求数。This metric reflects the number of incoming server requests that were received by your web application.

requests
| summarize sum(itemCount) by bin(timestamp, 5m)
| render barchart

服务器响应时间 (requests/duration)Server response time (requests/duration)

此指标反映服务器处理传入请求所花费的时间。This metric reflects the time it took for the servers to process incoming requests.

requests
| where notempty(duration)
| extend request_duration = iif(itemType == 'request', duration, todouble(''))
| extend _sum = request_duration
| extend _count = itemCount
| extend _sum = _sum*_count
| summarize sum(_sum) / sum(_count) by bin(timestamp, 1m)
| render timechart

使用指标Usage metrics

页面查看次数加载时间 (pageViews/duration)Page view load time (pageViews/duration)

此指标是指加载 PageView 事件所花费的时间。This metric refers to the amount of time it took for PageView events to load.

pageViews
| where notempty(duration)
| extend pageView_duration = iif(itemType == 'pageView', duration, todouble(''))
| extend _sum = pageView_duration
| extend _count = itemCount
| extend _sum = _sum * _count
| summarize sum(_sum) / sum(_count) by bin(timestamp, 5m)
| render barchart

页面查看次数 (pageViews/count)Page views (pageViews/count)

使用 TrackPageView () Application Insights API 记录的 PageView 事件计数。The count of PageView events logged with the TrackPageView() Application Insights API.

pageViews
| summarize sum(itemCount) by bin(timestamp, 1h)
| render barchart

会话数 (sessions/count)Sessions (sessions/count)

此指标是指不同会话 ID 的计数。This metric refers to the count of distinct session IDs.

union traces, requests, pageViews, dependencies, customEvents, availabilityResults, exceptions, customMetrics, browserTimings
| where notempty(session_Id)
| summarize dcount(session_Id) by bin(timestamp, 1h)
| render barchart

跟踪数 (traces/count)Traces (traces/count)

使用 TrackTrace () Application Insights API 调用记录的跟踪语句计数。The count of trace statements logged with the TrackTrace() Application Insights API call.

traces
| summarize sum(itemCount) by bin(timestamp, 1h)
| render barchart

用户数 (users/count)Users (users/count)

访问应用程序的不同用户的数目。The number of distinct users who accessed your application. 使用遥测采样和筛选可能会显著影响此指标的准确性。The accuracy of this metric may be significantly impacted by using telemetry sampling and filtering.

union traces, requests, pageViews, dependencies, customEvents, availabilityResults, exceptions, customMetrics, browserTimings
| where notempty(user_Id)
| summarize dcount(user_Id) by bin(timestamp, 1h)
| render barchart

经过身份验证的用户数 (users/authenticated)Users, Authenticated (users/authenticated)

在应用程序中进行身份验证的不同用户的数目。The number of distinct users who authenticated into your application.

union traces, requests, pageViews, dependencies, customEvents, availabilityResults, exceptions, customMetrics, browserTimings
| where notempty(user_AuthenticatedId)
| summarize dcount(user_AuthenticatedId) by bin(timestamp, 1h)
| render barchart