Kafka 生产者指标未出现在 Spring Boot 3.1.1 Prometheus 中

问题描述 投票:0回答:1

我有一个 Spring Boot 3.1.1 组件,我刚刚在其上创建了一些 Kafka 生产者。我希望在 Prometheus 中公开他们的指标,所以我做了以下配置:

@Autowired
private MeterRegistry meterRegistry;

@Bean
public KafkaTemplate<String, StatusEvent> statusEventKafkaTemplate(KafkaConfig kafkaConfig) {
  var config = kafkaConfig.buildProducerProperties();
  var factory = new DefaultKafkaProducerFactory<String, StatusEvent>(config);
  factory.addListener(new MicrometerProducerListener<>(meterRegistry));
  return new KafkaTemplate<>(factory);
}

但是,当我检查 Prometheus 时,只有

spring_kafka_template_seconds_max
spring_kafka_template_seconds

我在另一个项目中看到他们有更多负载:

kafka_producer_request_latency_avg
kafka_producer_record_retry_total
等。他们正在使用
org.springframework.kafka.core.reactive.ReactiveKafkaProducerTemplate
,但我希望(如果可能的话)找到一个与
org.springframework.kafka.core.KafkaTemplate
配合使用的解决方案。

以下是我认为相关的属性:

  • 应用程序属性
    management.endpoint.prometheus.enabled=true
    management.endpoints.web.exposure.include=*
    management.endpoint.health.show-details=ALWAYS
    spring.config.import=classpath:kafka-properties.yaml
    
  • kafka-properties.yaml
    spring:
        kafka:
            bootstrap-servers: [...]
            security:
                protocol: SASL_SSL
            properties:
                sasl:
                    mechanism: PLAIN
                    jaas:
                        config: [...]
                producers:
                    client-id: [...]
                    acks: all
    kafka:
        properties:
            status-events:
                template:
                    default-topic: [...]
                producer:
                    key-serializer: org.apache.kafka.common.serialization.StringDeserializer
                    value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
            [...]
    

我尝试将 spring-boot-starter-actuator 和 micrometer-registry-jmx 添加到我的依赖项中,但无济于事。我在我的属性中尝试使用

spring.jmx.enabled=true
。我的依赖项中已经有 micrometer-registry-prometheus。

执行器中出现的生产者指标我缺少什么?或者这是不可能的,我应该切换到反应堆?

spring-boot spring-kafka metrics spring-boot-actuator
1个回答
0
投票

最终我的配置是正确的。事实证明,只要生产者不发送任何内容,指标就不会显示在执行器中。

© www.soinside.com 2019 - 2024. All rights reserved.