Kafka Metrics

Kafka 绑定模块公开了以下指标:

Kafka binder module exposes the following metrics:

spring.cloud.stream.binder.kafka.offset:此指标表示尚未被给定绑定主题中的给定消费组使用自给定绑定主题的多少条消息。提供的指标基于 Micrometer 库。如果类路径上存在 Micrometer,并且应用程序没有提供其他此類 bean,则绑定会创建 KafkaBinderMetrics bean。此指标包含消费组信息、主题以及主题上最近偏移量与已提交偏移量之间的实际滞后。此指标对于向 PaaS 平台提供自动缩放反馈特别有用。

spring.cloud.stream.binder.kafka.offset: This metric indicates how many messages have not been yet consumed from a given binder’s topic by a given consumer group. The metrics provided are based on the Micrometer library. The binder creates the KafkaBinderMetrics bean if Micrometer is on the classpath and no other such beans provided by the application. The metric contains the consumer group information, topic and the actual lag in committed offset from the latest offset on the topic. This metric is particularly useful for providing auto-scaling feedback to a PaaS platform.

可以通过在 spring.cloud.stream.kafka.binder.metrics 命名空间中设置属性来配置指标收集行为,有关详细信息,请参阅 [kafka 绑定属性部分,kafka-binder-properies]

The metric collection behaviour can be configured by setting properties in the spring.cloud.stream.kafka.binder.metrics namespace, refer to the kafka-binder-properties for more information.

可以通过在应用程序中提供以下组件,从 KafkaBinderMetrics 中排除创建必要的基础设施(例如消费者),然后再报告指标。

You can exclude KafkaBinderMetrics from creating the necessary infrastructure like consumers and then reporting the metrics by providing the following component in the application.

@Component
class NoOpBindingMeters {
	NoOpBindingMeters(MeterRegistry registry) {
		registry.config().meterFilter(
				MeterFilter.denyNameStartsWith(KafkaBinderMetrics.OFFSET_LAG_METRIC_NAME));
	}
}

有关如何选择性禁止量表的更多详细信息,请参阅 here

More details on how to suppress meters selectively can be found here.