本文介绍使用 System.Diagnostics.Metrics API 生成的 ASP.NET Core 的内置指标。 For a listing of metrics based on the older EventCounters API, see Available counters.
有关如何使用 ASP.NET 核心指标收集、报告、扩充和测试的信息,请参阅 ASP.NET 核心指标。
Microsoft.AspNetCore.Components
指标 Microsoft.AspNetCore.Components
报告有关 Razor 组件路由更改和浏览器事件的信息:
指标:aspnetcore.components.navigation
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.components.navigation |
Counter |
{route} |
跟踪应用中的路由更改总数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.components.type |
字符串 |
导航到的组件。 |
TestComponent |
Always |
aspnetcore.components.route |
字符串 |
组件的路由。 |
/test-route |
Always |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果引发异常。 |
使用情况:用户访问了多少个不同的 Blazor 页面?
指标:aspnetcore.components.event_handler
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.components.event_handler |
Histogram |
s |
度量处理浏览器事件的持续时间,包括组件的业务逻辑,不包括子组件事件处理的持续时间。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.components.type |
字符串 |
处理事件的组件类型。 |
TestComponent |
Always |
aspnetcore.components.method |
字符串 |
处理事件的 C# 方法。 |
OnClick |
Always |
aspnetcore.components.attribute.name |
字符串 |
处理事件的组件属性名称。 |
onclick |
Always |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果引发异常。 |
Usage:
- 哪个组件的单击事件处理程序速度较慢?
- 经常选择哪些按钮?
Microsoft.AspNetCore.Components.Lifecycle
指标 Microsoft.AspNetCore.Components.Lifecycle
报告有关 Razor 组件生命周期事件的信息:
指标:aspnetcore.components.update_parameters
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.components.update_parameters |
Histogram |
s |
度量处理组件参数(包括业务逻辑)的持续时间。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.components.type |
字符串 |
处理事件的组件类型。 |
TestComponent |
Always |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果引发异常。 |
Usage:
指标:aspnetcore.components.render_diff
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.components.render_diff |
Histogram |
s |
跟踪呈现批处理的持续时间。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.components.diff.length |
int |
批处理的呈现差异/大小的长度(已存储)。 |
50 |
Always |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果引发异常。 |
Usage:
- 服务器呈现速度较慢吗?
- 是否呈现过大的差异? (网络带宽,DOM 更新)
Microsoft.AspNetCore.Components.Server.Circuits
指标Microsoft.AspNetCore.Components.Server.Circuits
报告服务器端Blazor线路的信息Blazor ServerBlazor Web App,
指标:aspnetcore.components.circuit.active
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.components.circuit.active |
UpDownCounter |
{circuit} |
显示当前内存中的活动线路数。 |
使用情况:会话状态保留多少内存?
指标:aspnetcore.components.circuit.connected
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.components.circuit.connected |
UpDownCounter |
{circuit} |
跟踪连接到客户端的线路数。 |
用法:打开了多少 SignalR 个连接?
指标:aspnetcore.components.circuit.duration
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.components.circuit.duration |
Histogram |
s |
测量线路生存期持续时间并提供总线路计数。 |
Usage:
- 处理了多少个会话?
- 用户保持会话/选项卡打开多长时间?
Microsoft.AspNetCore.Hosting
指标 Microsoft.AspNetCore.Hosting
报告有关 ASP.NET Core 收到的 HTTP 请求的高级信息:
指标:http.server.request.duration
Attribute |
类型 |
Description |
Examples |
Presence |
http.route |
字符串 |
匹配的路由。 |
{controller}/{action}/
{id?} |
如果可用。 |
error.type |
字符串 |
描述操作结束的错误类。 |
timeout ;name_resolution_error ;500 |
如果请求已以错误结束。 |
http.request.method |
字符串 |
HTTP 请求方法。 |
GET ;POST ;HEAD |
Always |
http.response.status_code |
int |
HTTP 响应状态代码。 |
200 |
如果发送了一个。 |
network.protocol.version |
字符串 |
中指定的 network.protocol.name 协议的版本。 |
3.1.1 |
Always |
url.scheme |
字符串 |
The URI scheme component identifying the used protocol. |
http ;https |
Always |
aspnetcore.request.is_unhandled |
布尔 |
如果应用程序管道未处理请求,则为 True。 |
true |
如果请求未处理。 |
在 ASP.NET Core 的托管层测量的入站 HTTP 请求所用的时间。 基础 Web 主机具有以下功能后开始时间度量:
- 充分分析入站网络流上的 HTTP 请求标头,以标识新请求。
- 初始化上下文数据结构,如 HttpContext.
时间结束时间:
- ASP.NET 核心处理程序管道已完成执行。
- 已发送所有响应数据。
- 正在释放请求的上下文数据结构。
使用 OpenTelemetry 时,此指标的默认存储桶设置为 [ 0.005、0.01、0.025、0.05、0.075、0.1、0.25、0.5、0.75、1、2.5、5、7.5、10 ]。
指标:http.server.active_requests
Attribute |
类型 |
Description |
Examples |
Presence |
http.request.method |
字符串 |
HTTP 请求方法。 [1] |
GET ;POST ;HEAD |
Always |
url.scheme |
字符串 |
The URI scheme component identifying the used protocol. |
http ;https |
Always |
Microsoft.AspNetCore.Routing
指标 Microsoft.AspNetCore.Routing
报告有关 将 HTTP 请求路由 到 ASP.NET 核心终结点的信息:
指标:aspnetcore.routing.match_attempts
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.routing.match_status |
字符串 |
Match result |
success ;failure |
Always |
aspnetcore.routing.is_fallback_route |
boolean |
一个值,该值指示匹配的路由是否为回退路由。 |
True |
如果已成功匹配路由。 |
http.route |
字符串 |
匹配的路由 |
{controller}/{action}/
{id?} |
如果已成功匹配路由。 |
Microsoft.AspNetCore.Diagnostics
指标 Microsoft.AspNetCore.Diagnostics
报告 来自 ASP.NET 核心错误处理中间件的诊断信息:
指标:aspnetcore.diagnostics.exceptions
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.diagnostics.exception.result |
字符串 |
ASP.NET 核心异常中间件处理结果 |
handled ;unhandled |
Always |
aspnetcore.diagnostics.handler.type |
字符串 |
处理异常的实现的 IExceptionHandler 全类型名称。 |
Contoso.MyHandler |
如果此处理程序处理了异常。 |
exception.type |
字符串 |
异常类型的全名。 |
System.OperationCanceledException ;Contoso.MyException |
Always |
Microsoft.AspNetCore.RateLimiting
指标 Microsoft.AspNetCore.RateLimiting
报告 来自 ASP.NET 核心速率限制中间件的速率限制信息:
指标:aspnetcore.rate_limiting.active_request_leases
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.rate_limiting.policy |
字符串 |
速率限制策略名称。 |
fixed ;sliding ;token |
如果请求的匹配终结点具有速率限制策略。 |
指标:aspnetcore.rate_limiting.request_lease.duration
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.rate_limiting.policy |
字符串 |
速率限制策略名称。 |
fixed ;sliding ;token |
如果请求的匹配终结点具有速率限制策略。 |
指标:aspnetcore.rate_limiting.queued_requests
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.rate_limiting.policy |
字符串 |
速率限制策略名称。 |
fixed ;sliding ;token |
如果请求的匹配终结点具有速率限制策略。 |
指标:aspnetcore.rate_limiting.request.time_in_queue
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.rate_limiting.policy |
字符串 |
速率限制策略名称。 |
fixed ;sliding ;token |
如果请求的匹配终结点具有速率限制策略。 |
aspnetcore.rate_limiting.result |
字符串 |
速率限制结果显示是获取租约还是包含拒绝原因。 |
acquired ;request_canceled |
Always |
指标:aspnetcore.rate_limiting.requests
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.rate_limiting.policy |
字符串 |
速率限制策略名称。 |
fixed ;sliding ;token |
如果请求的匹配终结点具有速率限制策略。 |
aspnetcore.rate_limiting.result |
字符串 |
速率限制结果显示是获取租约还是包含拒绝原因。 |
acquired ;request_canceled |
Always |
指标 Microsoft.AspNetCore.HeaderParsing
报告 有关 ASP.NET Core 标头分析的信息:
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.header_parsing.parse_errors |
Counter |
{parse_error} |
分析 HTTP 请求标头时发生的错误数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.header_parsing.header.name |
字符串 |
标头名称。 |
Content-Type |
Always |
error.type |
字符串 |
错误消息。 |
Unable to parse media type value. |
Always |
仅针对支持缓存的 HTTP 请求标头分析程序发出指标。
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.header_parsing.cache_accesses |
Counter |
{cache_access} |
访问存储已分析标头值的缓存的次数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.header_parsing.header.name |
字符串 |
标头名称。 |
Content-Type |
Always |
aspnetcore.header_parsing.cache_access.type |
字符串 |
一个值,该值指示是否在缓存中找到标头的值。 |
Hit ;Miss |
Always |
Microsoft.AspNetCore.Server.Kestrel
指标 Microsoft.AspNetCore.Server.Kestrel
报告 来自 ASP.NET Core Kestrel Web 服务器的 HTTP 连接信息:
指标:kestrel.active_connections
Attribute |
类型 |
Description |
Examples |
Presence |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
指标:kestrel.connection.duration
Attribute |
类型 |
Description |
Examples |
Presence |
error.type |
字符串 |
描述连接结束的错误类型,或连接管道期间引发的未经处理的异常类型。 可以在 Web 服务器指标的语义约定Kestrel中找到已知的连接错误。 |
connection_reset ;invalid_request_headers ;System.OperationCanceledException |
如果连接以已知错误结束或引发异常。 |
network.protocol.name |
字符串 |
OSI 应用程序层或非 OSI 等效层 。 |
http ;web_sockets |
Always |
network.protocol.version |
字符串 |
中指定的 network.protocol.name 协议的版本。 |
1.1 ;2 |
Always |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
tls.protocol.version |
字符串 |
TLS 协议版本。 |
1.2 ;1.3 |
如果连接使用 TLS 进行保护。 |
由于此指标正在跟踪连接持续时间,理想情况下,http 连接用于多个请求,因此存储桶应比用于请求持续时间的存储桶长。 例如,使用 [ 0.01、0.02、0.05、0.1、0.2、0.5、1、2、5、10、30、60、120、300] 提供 5 分钟大桶。
指标:kestrel.rejected_connections
Attribute |
类型 |
Description |
Examples |
Presence |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
当当前活动计数超过配置 MaxConcurrentConnections
的值时,将拒绝连接。
指标:kestrel.queued_connections
Attribute |
类型 |
Description |
Examples |
Presence |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
指标:kestrel.queued_requests
Name |
Instrument Type |
Unit (UCUM) |
Description |
kestrel.queued_requests |
UpDownCounter |
{request} |
多路复用连接(HTTP/2 和 HTTP/3)上的 HTTP 请求数,这些请求当前已排队并正在等待启动。 |
Attribute |
类型 |
Description |
Examples |
Presence |
network.protocol.name |
字符串 |
OSI 应用程序层或非 OSI 等效层 。 |
http ;web_sockets |
Always |
network.protocol.version |
字符串 |
中指定的 network.protocol.name 协议的版本。 |
1.1 ;2 |
Always |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
指标:kestrel.upgraded_connections
Attribute |
类型 |
Description |
Examples |
Presence |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
计数器仅跟踪 HTTP/1.1 连接。
指标:kestrel.tls_handshake.duration
Attribute |
类型 |
Description |
Examples |
Presence |
error.type |
字符串 |
异常类型的全名。 |
System.OperationCanceledException ;Contoso.MyException |
如果引发了异常。 |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
tls.protocol.version |
字符串 |
TLS 协议版本。 |
1.2 ;1.3 |
如果连接使用 TLS 进行保护。 |
使用 OpenTelemetry 时,此 metic 的默认存储桶设置为 [ 0.005、0.01、0.025、0.05、0.075、0.1、0.25、0.5、0.75、1、2.5、5、7.5、10 ]。
指标:kestrel.active_tls_handshakes
Attribute |
类型 |
Description |
Examples |
Presence |
network.transport |
字符串 |
OSI 传输层 或 进程间通信方法。 |
tcp ;unix |
Always |
network.type |
字符串 |
OSI 网络层 或非 OSI 等效项。 |
ipv4 ;ipv6 |
如果传输为 tcp 或 udp 。 |
server.address |
字符串 |
如果没有反向 DNS 查找,则服务器地址域名可用;否则为 IP 地址或 Unix 域套接字名称。 |
example.com |
Always |
server.port |
int |
服务器端口号 |
80 ;8080 ;443 |
如果传输为 tcp 或 udp 。 |
Microsoft.AspNetCore.Http.Connections
指标 Microsoft.AspNetCore.Http.Connections
报告 来自 ASP.NET 核心 SignalR的连接信息:
指标:signalr.server.connection.duration
Attribute |
类型 |
Description |
Examples |
Presence |
signalr.connection.status |
字符串 |
SignalR HTTP 连接关闭状态。 |
app_shutdown ;timeout |
Always |
signalr.transport |
字符串 |
SignalR 传输类型 |
web_sockets ;long_polling |
Always |
Value |
Description |
normal_closure |
连接正常关闭。 |
timeout |
由于超时,连接已关闭。 |
app_shutdown |
连接已关闭,因为应用正在关闭。 |
signalr.transport
是以下项之一:
由于此指标跟踪连接持续时间,理想情况下 SignalR 连接是持久的,因此存储桶应比请求持续时间使用的持续时间长。 例如,使用 [0, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300] 提供 5 分钟的高桶。
指标:signalr.server.active_connections
Attribute |
类型 |
Description |
Examples |
Presence |
signalr.connection.status |
字符串 |
SignalR HTTP 连接关闭状态。 |
app_shutdown ;timeout |
Always |
signalr.transport |
字符串 |
SignalR 传输类型 |
web_sockets ;long_polling |
Always |
Microsoft.AspNetCore.Authorization
The Microsoft.AspNetCore.Authorization
metrics report information about Authorization attempts in ASP.NET Core apps:
指标:aspnetcore.authorization.attempts
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.authorization.attempts |
Counter |
{request} |
尝试授权的请求总数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
user.is_authenticated |
boolean |
请求是否来自经过身份验证的用户 |
true |
Required |
aspnetcore.authorization.policy |
字符串 |
授权策略的名称。 |
AtLeast21 ;EmployeeOnly |
Conditionally required 如果使用授权策略。 |
aspnetcore.authorization.result |
字符串 |
授权是成功还是失败。 |
success ;failure |
Conditionally Required 如果在授权期间未引发异常,则为 。 |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果请求已以错误结束,则为 。 |
Microsoft.AspNetCore.Authentication
The Microsoft.AspNetCore.Authentication
metrics report information about Authentication in ASP.NET Core apps:
指标:aspnetcore.authentication.authenticate.duration
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.authentication.authenticate.duration |
Histogram |
s |
请求的身份验证持续时间。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.authentication.result |
字符串 |
身份验证结果。 |
success ;failure ;none ;_OTHER |
如果请求未以错误结尾,则为 。 |
aspnetcore.authentication.scheme |
字符串 |
身份验证方案的名称。 |
Bearer ;Cookies |
如果请求未以错误结尾,则为 。 |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
Conditionally Required 如果身份验证失败或请求,则为 已以错误结束。 |
指标:aspnetcore.authentication.challenges
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.authentication.challenges |
Counter |
{request} |
对方案提出质询的总次数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.authentication.scheme |
字符串 |
身份验证方案的名称。 |
Bearer ;Cookies |
如果请求未以错误结尾,则为 。 |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果请求已以错误结束,则为 。 |
指标:aspnetcore.authentication.forbids
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.authentication.forbids |
Counter |
{request} |
经过身份验证的用户尝试访问其不允许访问的资源的总次数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.authentication.scheme |
字符串 |
身份验证方案的名称。 |
Bearer ;Cookies |
如果请求未以错误结尾,则为 。 |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果请求已以错误结束,则为 。 |
指标:aspnetcore.authentication.sign_ins
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.authentication.sign_ins |
Counter |
{request} |
主体使用方案登录的总次数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.authentication.scheme |
字符串 |
身份验证方案的名称。 |
Bearer ;Cookies |
如果请求未以错误结尾,则为 。 |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果请求已以错误结束,则为 。 |
指标:aspnetcore.authentication.sign_outs
Name |
Instrument Type |
Unit (UCUM) |
Description |
aspnetcore.authentication.sign_outs |
Counter |
{request} |
主体使用方案注销的总次数。 |
Attribute |
类型 |
Description |
Examples |
Presence |
aspnetcore.authentication.scheme |
字符串 |
身份验证方案的名称。 |
Bearer ;Cookies |
如果请求未以错误结尾,则为 。 |
error.type |
字符串 |
异常类型的全名。 |
System.InvalidOperationException ;Contoso.MyException |
如果请求已以错误结束,则为 。 |