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

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

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

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

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

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

  • Java

  • XML

@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 开始,应用程序上下文中存在千分尺会触发对千分尺度量的支持。MeterRegistry

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

对于每个 和 ,都注册了计时器。 对于每个 ,注册一个计数器。MessageHandlerMessageChannelMessageSource

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

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

  • name:spring.integration.send

  • tag:type:channel

  • tag:name:<componentName>

  • tag:result:(success|failure)

  • tag:exception:(none|exception simple class name)

  • description:Send processing time

(有异常的结果表示返回通道的操作。failurenonesend()false

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

  • name:spring.integration.receive

  • tag:type:channel

  • tag:name:<componentName>

  • tag:result:(success|failure)

  • tag:exception:(none|exception simple class name)

  • description:Messages received

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

  • name:spring.integration.send

  • tag:type:handler

  • tag:name:<componentName>

  • tag:result:(success|failure)

  • tag:exception:(none|exception simple class name)

  • description:Send processing time

消息源的计量器具有以下名称/标签:Counter

  • name:spring.integration.receive

  • tag:type:source

  • tag:name:<componentName>

  • tag:result:success

  • tag:exception:none

  • description:Messages received

此外,还有三个仪表:Gauge

  • spring.integration.channels:应用程序中的编号。MessageChannels

  • spring.integration.handlers:应用程序中的编号。MessageHandlers

  • spring.integration.sources:应用程序中的编号。MessageSources

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

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

  • name:spring.integration.channel.queue.size

  • tag:type:channel

  • tag:name:<componentName>

  • description:The size of the queue channel

  • name:spring.integration.channel.queue.remaining.capacity

  • tag:type:channel

  • tag:name:<componentName>

  • description:The remaining capacity of the queue channel

禁用仪表

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

例如,给定:

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

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

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

千分尺观察

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

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

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

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

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

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

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

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

  • an 是 span 类型,使用 API。AbstractMessageHandlerCONSUMERIntegrationObservation.HANDLER

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

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

可观测性 - 指标

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

网关

观察入站消息网关。

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

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

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

封闭类 .o.s.i.support.management.observation.IntegrationObservation

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

名字

描述

spring.integration.name (必填)

消息网关组件的名称。

spring.integration.outcome (必填)

请求/应答执行的结果。

spring.integration.type (必填)

组件类型 - “gateway”。

处理器

观察消息处理程序。

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

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

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

封闭类 .o.s.i.support.management.observation.IntegrationObservation

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件的类型 - “handler”。

制作人

对消息生产者的观察,例如渠道。

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

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

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

封闭类 .o.s.i.support.management.observation.IntegrationObservation

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件类型 - “producer”。

可观测性 - 跨度

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

网关跨度

观察入站消息网关。

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

封闭类 .o.s.i.support.management.observation.IntegrationObservation

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

名字

描述

spring.integration.name (必填)

消息网关组件的名称。

spring.integration.outcome (必填)

请求/应答执行的结果。

spring.integration.type (必填)

组件类型 - “gateway”。

处理程序跨度

观察消息处理程序。

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

封闭类 .o.s.i.support.management.observation.IntegrationObservation

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件的类型 - “handler”。

制片人跨度

对消息生产者的观察,例如渠道。

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

封闭类 .o.s.i.support.management.observation.IntegrationObservation

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件类型 - “producer”。

可观测性 - 约定

您可以在下面找到该项目声明的所有列表。GlobalObservationConventionObservationConvention

表 7.观察公约实现

ObservationConvention 类名称

适用的 ObservationContext 类名

o.s.i.support.management.observation.DefaultMessageReceiverObservationConvention

MessageReceiverContext

o.s.i.support.management.observation.MessageReceiverObservationConvention

MessageReceiverContext

o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConvention

MessageRequestReplyReceiverContext

o.s.i.support.management.observation.MessageRequestReplyReceiverObservationConvention

MessageRequestReplyReceiverContext

o.s.i.support.management.observation.DefaultMessageSenderObservationConvention

MessageSenderContext

o.s.i.support.management.observation.MessageSenderObservationConvention

MessageSenderContext

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

名字

描述

spring.integration.name (必填)

消息网关组件的名称。

spring.integration.outcome (必填)

请求/应答执行的结果。

spring.integration.type (必填)

组件类型 - “gateway”。

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件的类型 - “handler”。

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件类型 - “producer”。

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

名字

描述

spring.integration.name (必填)

消息网关组件的名称。

spring.integration.outcome (必填)

请求/应答执行的结果。

spring.integration.type (必填)

组件类型 - “gateway”。

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件的类型 - “handler”。

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

名字

描述

spring.integration.name (必填)

消息处理程序组件的名称。

spring.integration.type (必填)

组件类型 - “producer”。

表 7.观察公约实现

ObservationConvention 类名称

适用的 ObservationContext 类名

o.s.i.support.management.observation.DefaultMessageReceiverObservationConvention

MessageReceiverContext

o.s.i.support.management.observation.MessageReceiverObservationConvention

MessageReceiverContext

o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConvention

MessageRequestReplyReceiverContext

o.s.i.support.management.observation.MessageRequestReplyReceiverObservationConvention

MessageRequestReplyReceiverContext

o.s.i.support.management.observation.DefaultMessageSenderObservationConvention

MessageSenderContext

o.s.i.support.management.observation.MessageSenderObservationConvention

MessageSenderContext

观测传播

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

Spring Integration JMX 支持

另请参阅 JMX 支持