此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

本节介绍如何捕获 Spring Integration 的指标。 在最近的版本中,我们更多地依赖 Micrometer(参见 micrometer.io),我们计划在未来的版本中更多地使用 Micrometer。Spring中文文档

在大容量环境中禁用日志记录

您可以在主消息流中控制调试日志记录。 在非常大容量的应用程序中,对某些日志记录子系统的调用可能非常昂贵。 您可以禁用所有此类日志记录以避免此开销。 异常日志记录(调试或其他)不受此设置的影响。isDebugEnabled()Spring中文文档

以下列表显示了用于控制日志记录的可用选项:Spring中文文档

@Configuration
@EnableIntegration
@EnableIntegrationManagement(
    defaultLoggingEnabled = "true" <1>)

public static class ContextConfiguration {
...
}
<int:management default-logging-enabled="true"/> (1)
1 设置为可禁用主消息流中的所有日志记录,而不考虑日志系统类别设置。 设置为“true”以启用调试日志记录(如果日志记录子系统也启用了)。 仅当尚未在 Bean 定义中显式配置该设置时才适用。 默认值为 。falsetrue
defaultLoggingEnabled仅当尚未在 Bean 定义中显式配置相应的设置时,才应用。
1 设置为可禁用主消息流中的所有日志记录,而不考虑日志系统类别设置。 设置为“true”以启用调试日志记录(如果日志记录子系统也启用了)。 仅当尚未在 Bean 定义中显式配置该设置时才适用。 默认值为 。falsetrue
defaultLoggingEnabled仅当尚未在 Bean 定义中显式配置相应的设置时,才应用。

千分尺集成

概述

从版本 5.0.3 开始,应用程序上下文中存在千分尺会触发对千分尺度量的支持。MeterRegistrySpring中文文档

要使用 Micrometer,请将其中一个 Bean 添加到应用程序上下文中。MeterRegistrySpring中文文档

对于每个 和 ,都注册了计时器。 对于每个 ,注册一个计数器。MessageHandlerMessageChannelMessageSourceSpring中文文档

这仅适用于扩展 、 和 的对象(大多数框架组件都是这种情况)。AbstractMessageHandlerAbstractMessageChannelAbstractMessageSourceSpring中文文档

用于在消息通道上执行发送操作的计量具有以下名称或标记:TimerSpring中文文档

(有异常的结果表示返回通道的操作。failurenonesend()falseSpring中文文档

用于在可轮询消息通道上执行接收操作的计量具有以下名称或标记:CounterSpring中文文档

用于对消息处理程序进行操作的计量具有以下名称或标记:TimerSpring中文文档

消息源的计量器具有以下名称/标签:CounterSpring中文文档

此外,还有三个仪表:GaugeSpring中文文档

  • spring.integration.channels:应用程序中的编号。MessageChannelsSpring中文文档

  • spring.integration.handlers:应用程序中的编号。MessageHandlersSpring中文文档

  • spring.integration.sources:应用程序中的编号。MessageSourcesSpring中文文档

可以通过提供 的子类来自定义集成组件创建的名称和标签。 MicrometerCustomMetricsTests 测试用例显示了如何执行此操作的简单示例。 您还可以通过重载构建器子类上的方法来进一步自定义度量。MetersMicrometerMetricsCaptorbuild()Spring中文文档

从版本 5.1.13 开始,公开队列大小和剩余容量的千分尺仪:QueueChannelSpring中文文档

禁用仪表

默认情况下,所有测量仪在首次使用时都会注册。 现在,使用 Micrometer,您可以将 s 添加到 中,以防止部分或全部被注册。 您可以按提供的任何属性(、、)等过滤掉(拒绝)仪表。 有关详细信息,请参阅千分尺文档中的仪表滤波器MeterFilterMeterRegistrynametagSpring中文文档

例如,给定:Spring中文文档

@Bean
public QueueChannel noMeters() {
    return new QueueChannel(10);
}

您可以使用以下命令禁止注册此通道的仪表:Spring中文文档

registry.config().meterFilter(MeterFilter.deny(id ->
        "channel".equals(id.getTag("type")) &&
        "noMeters".equals(id.getTag("name"))));

千分尺观察

从 6.0 版开始,Spring Integration 利用了 Micrometer Observation 抽象,它可以通过适当的配置处理度量和跟踪ObservationHandlerSpring中文文档

每当应用程序上下文中存在 Bean 并配置了 Bean 时,就会在组件上启用观察处理。 要自定义应检测的组件集,将在注释上公开一个属性。 请参阅其 javadocs 以获取模式匹配算法。IntegrationManagementObservationRegistry@EnableIntegrationManagementobservationPatterns()@EnableIntegrationManagementSpring中文文档

缺省情况下,任何组件都不使用 Bean 进行检测。 可以配置为匹配所有组件。IntegrationManagementObservationRegistry*

在这种情况下,计量器不是独立收集的,而是委托给在提供的 .ObservationHandlerObservationRegistrySpring中文文档

以下 Spring Integration 组件都使用观察逻辑进行检测,每个组件都有各自的约定:Spring中文文档

  • MessageProducerSupport,作为流的入站终结点,被视为跨度类型并使用 API;CONSUMERIntegrationObservation.HANDLERSpring中文文档

  • MessagingGatewaySupport' 是一个入站请求-答复终结点,被视为 span 类型。 它使用 API;SERVERIntegrationObservation.GATEWAYSpring中文文档

  • 操作是生成消息的唯一 Spring Integration API。 因此,它被视为 span 类型并使用 API。 当通道是分布式实现时,这更有意义(例如 或 ),并且必须将跟踪信息添加到消息中。 因此,观察结果基于 Spring Integration 提供的 a 以允许后续跟踪添加标头,以便它们可供使用者使用;AbstractMessageChannel.send()PRODUCERIntegrationObservation.PRODCUERPublishSubscribeKafkaChannelZeroMqChannelIntegrationObservation.PRODUCERMessageSenderContextMutableMessagePropagatorSpring中文文档

  • an 是 span 类型,使用 API。AbstractMessageHandlerCONSUMERIntegrationObservation.HANDLERSpring中文文档

组件的观察生产可以通过配置进行定制。 例如,an 期望通过其 API。IntegrationManagementObservationConventionAbstractMessageHandlerMessageReceiverObservationConventionsetObservationConvention()Spring中文文档

以下是观察 API 支持的指标、跨度和约定:Spring中文文档

可观测性 - 指标

您可以在下面找到此项目声明的所有指标的列表。Spring中文文档

网关

观察入站消息网关。Spring中文文档

指标名称(由约定类定义)。键入spring.integration.gatewayo.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConventiontimerSpring中文文档

指标名称(由约定类定义)。键入spring.integration.gateway.activeo.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConventionlong task timerSpring中文文档

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds

封闭类 .o.s.i.support.management.observation.IntegrationObservationSpring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 1.低基数键

spring.integration.name (必填)Spring中文文档

消息网关组件的名称。Spring中文文档

spring.integration.outcome (必填)Spring中文文档

请求/应答执行的结果。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “gateway”。Spring中文文档

处理器

观察消息处理程序。Spring中文文档

指标名称(由约定类定义)。键入spring.integration.handlero.s.i.support.management.observation.DefaultMessageReceiverObservationConventiontimerSpring中文文档

指标名称(由约定类定义)。键入spring.integration.handler.activeo.s.i.support.management.observation.DefaultMessageReceiverObservationConventionlong task timerSpring中文文档

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds

封闭类 .o.s.i.support.management.observation.IntegrationObservationSpring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 2.低基数键

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件的类型 - “handler”。Spring中文文档

制作人

对消息生产者的观察,例如渠道。Spring中文文档

指标名称(由约定类定义)。键入spring.integration.producero.s.i.support.management.observation.DefaultMessageSenderObservationConventiontimerSpring中文文档

指标名称(由约定类定义)。键入spring.integration.producer.activeo.s.i.support.management.observation.DefaultMessageSenderObservationConventionlong task timerSpring中文文档

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds

封闭类 .o.s.i.support.management.observation.IntegrationObservationSpring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 3.低基数键

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “producer”。Spring中文文档

可观测性 - 跨度

您可以在下面找到此项目声明的所有跨度的列表。Spring中文文档

网关跨度

观察入站消息网关。Spring中文文档

Span 名称(由约定类定义)。spring.integration.gatewayo.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConventionSpring中文文档

封闭类 .o.s.i.support.management.observation.IntegrationObservationSpring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 4.标签键

名字Spring中文文档

描述Spring中文文档

spring.integration.name (必填)Spring中文文档

消息网关组件的名称。Spring中文文档

spring.integration.outcome (必填)Spring中文文档

请求/应答执行的结果。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “gateway”。Spring中文文档

处理程序跨度

观察消息处理程序。Spring中文文档

Span 名称(由约定类定义)。spring.integration.handlero.s.i.support.management.observation.DefaultMessageReceiverObservationConventionSpring中文文档

封闭类 .o.s.i.support.management.observation.IntegrationObservationSpring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 5.标签键

名字Spring中文文档

描述Spring中文文档

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件的类型 - “handler”。Spring中文文档

制片人跨度

对消息生产者的观察,例如渠道。Spring中文文档

Span 名称(由约定类定义)。spring.integration.producero.s.i.support.management.observation.DefaultMessageSenderObservationConventionSpring中文文档

封闭类 .o.s.i.support.management.observation.IntegrationObservationSpring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 6.标签键

名字Spring中文文档

描述Spring中文文档

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “producer”。Spring中文文档

可观测性 - 约定

您可以在下面找到该项目声明的所有列表。GlobalObservationConventionObservationConventionSpring中文文档

表 7.观察公约实现

ObservationConvention 类名称Spring中文文档

适用的 ObservationContext 类名Spring中文文档

o.s.i.support.management.observation.DefaultMessageReceiverObservationConventionSpring中文文档

MessageReceiverContextSpring中文文档

o.s.i.support.management.observation.MessageReceiverObservationConventionSpring中文文档

MessageReceiverContextSpring中文文档

o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConventionSpring中文文档

MessageRequestReplyReceiverContextSpring中文文档

o.s.i.support.management.observation.MessageRequestReplyReceiverObservationConventionSpring中文文档

MessageRequestReplyReceiverContextSpring中文文档

o.s.i.support.management.observation.DefaultMessageSenderObservationConventionSpring中文文档

MessageSenderContextSpring中文文档

o.s.i.support.management.observation.MessageSenderObservationConventionSpring中文文档

MessageSenderContextSpring中文文档

缺省情况下,任何组件都不使用 Bean 进行检测。 可以配置为匹配所有组件。IntegrationManagementObservationRegistry*
*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds
所有标签都必须以前缀为前缀!spring.integration.
表 1.低基数键

spring.integration.name (必填)Spring中文文档

消息网关组件的名称。Spring中文文档

spring.integration.outcome (必填)Spring中文文档

请求/应答执行的结果。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “gateway”。Spring中文文档

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds
所有标签都必须以前缀为前缀!spring.integration.
表 2.低基数键

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件的类型 - “handler”。Spring中文文档

*.active 指标中可能缺少在启动观察任务后添加的 KeyValues。
千分尺内部用于基本单元。但是,每个后端都决定了实际的基本单位。(即 Prometheus 使用秒)nanoseconds
所有标签都必须以前缀为前缀!spring.integration.
表 3.低基数键

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “producer”。Spring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 4.标签键

名字Spring中文文档

描述Spring中文文档

spring.integration.name (必填)Spring中文文档

消息网关组件的名称。Spring中文文档

spring.integration.outcome (必填)Spring中文文档

请求/应答执行的结果。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “gateway”。Spring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 5.标签键

名字Spring中文文档

描述Spring中文文档

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件的类型 - “handler”。Spring中文文档

所有标签都必须以前缀为前缀!spring.integration.
表 6.标签键

名字Spring中文文档

描述Spring中文文档

spring.integration.name (必填)Spring中文文档

消息处理程序组件的名称。Spring中文文档

spring.integration.type (必填)Spring中文文档

组件类型 - “producer”。Spring中文文档

表 7.观察公约实现

ObservationConvention 类名称Spring中文文档

适用的 ObservationContext 类名Spring中文文档

o.s.i.support.management.observation.DefaultMessageReceiverObservationConventionSpring中文文档

MessageReceiverContextSpring中文文档

o.s.i.support.management.observation.MessageReceiverObservationConventionSpring中文文档

MessageReceiverContextSpring中文文档

o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConventionSpring中文文档

MessageRequestReplyReceiverContextSpring中文文档

o.s.i.support.management.observation.MessageRequestReplyReceiverObservationConventionSpring中文文档

MessageRequestReplyReceiverContextSpring中文文档

o.s.i.support.management.observation.DefaultMessageSenderObservationConventionSpring中文文档

MessageSenderContextSpring中文文档

o.s.i.support.management.observation.MessageSenderObservationConventionSpring中文文档

MessageSenderContextSpring中文文档

观测传播

若要在一个跟踪中提供连接的跨度链,而与消息传递流的性质无关,即使 a 是持久性和分布式的,也必须在此通道和此通道的使用者(订阅者)上启用观察。 这样,跟踪信息在传播到使用者线程或持久保存到数据库之前存储在消息标头中。 这是通过上面提到的。 使用者 (a) 端使用 a 从这些标头中恢复跟踪信息,并启动一个新的子项。MessageChannelMessageSenderContextMessageHandlerMessageReceiverContextObservationSpring中文文档

Spring Integration JMX 支持