缺失的Metriks Spring Kafka监听器

huangapple go评论74阅读模式
英文:

missing metriks spring kafka listener

问题

I use KafkaListener to get a message from kafka, but I don't get the spring_kafka_listener metrics

使用KafkaListener来从Kafka获取消息,但我没有得到spring_kafka_listener指标

registering a metric with the name spring_kaf_ka_listener did not give results, an error message will appear that such a metric has already been registered

使用名称spring_kaf_ka_listener注册指标没有产生结果,将出现已经注册了这样的指标的错误消息

the addition did not give any result
cf.addListener(new MicrometerConsumerListener<>(new SimpleMeterRegistry()));

添加没有产生任何结果
cf.addListener(new MicrometerConsumerListener<>(new SimpleMeterRegistry()));

@Configuration
@EnableKafka
public class KafkaConsumerConfig {

    @Autowired
    private KafkaProperties kafkaProperties;

    @Bean
    public Map<String, Object> consumerConfigs() {
        Map<String, Object> props = new HashMap<>(kafkaProperties.buildConsumerProperties());
        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        props.put(ConsumerConfig.GROUP_ID_CONFIG, kafkaProperties.getConsumer().getGroupId());
        return props;
    }

    @Bean
    public ConsumerFactory<String, String> consumerFactory() {
        final StringDeserializer jsonDeserializer = new StringDeserializer();
        ConsumerFactory<String, String> cf = new DefaultKafkaConsumerFactory<>(
            kafkaProperties.buildConsumerProperties(),
            new StringDeserializer(), jsonDeserializer
        );
        //I tried to add it but it didn't give any result
        cf.addListener(new MicrometerConsumerListener<>(new SimpleMeterRegistry()));
        return cf;
    }

    @Bean
    public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
        ConcurrentKafkaListenerContainerFactory<String, String> factory =
            new ConcurrentKafkaListenerContainerFactory<>();
        factory.setConsumerFactory(consumerFactory());
        factory.setBatchListener(false);

        return factory;
    }

    @Bean
    public DefaultKafkaHeaderMapper headerMapper() {
        return new DefaultKafkaHeaderMapper();
    }
}
英文:

I use KafkaListener to get a message from kafka, but I don't get the spring_kafka_listener metrics

registering a metric with the name spring_kaf_ka_listener did not give results, an error message will appear that such a metric has already been registered

the addition did not give any result
cf.addListener(new MicrometerConsumerListener<>(new SimpleMeterRegistry()));

@Configuration
@EnableKafka
public class KafkaConsumerConfig {
@Autowired
private KafkaProperties kafkaProperties;
@Bean
public Map&lt;String, Object&gt; consumerConfigs() {
Map&lt;String, Object&gt; props = new HashMap&lt;&gt;(kafkaProperties.buildConsumerProperties());
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.GROUP_ID_CONFIG, kafkaProperties.getConsumer().getGroupId());
return props;
}
@Bean
public ConsumerFactory&lt;String, String&gt; consumerFactory() {
final StringDeserializer jsonDeserializer = new StringDeserializer();
ConsumerFactory&lt;String,String&gt; cf = new DefaultKafkaConsumerFactory&lt;&gt;(
kafkaProperties.buildConsumerProperties(),
new StringDeserializer(), jsonDeserializer
);
//I tried to add it but it didn&#39;t give any result
cf.addListener(new MicrometerConsumerListener&lt;&gt;(new SimpleMeterRegistry()));//
return cf;
}
@Bean
public ConcurrentKafkaListenerContainerFactory&lt;String, String&gt; kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory&lt;String, String&gt; factory =
new ConcurrentKafkaListenerContainerFactory&lt;&gt;();
factory.setConsumerFactory(consumerFactory());
factory.setBatchListener(false);
return factory;
}
@Bean
public DefaultKafkaHeaderMapper headerMapper() {
return new DefaultKafkaHeaderMapper();
}
}

答案1

得分: 0

消费者监听器启用了本机Kafka指标,spring_kafka_listener指标由micrometerEnabled容器属性控制,默认情况下为true。

https://docs.spring.io/spring-kafka/docs/current/reference/html/#micrometer

只有在类路径上存在Micrometer时才会捕获这些指标。

如果您无法弄清楚,请提供一个MCRE,以便我们看到问题出在哪里。

英文:

The consumer listener enables the native Kafka metrics, the spring_kafka_listener metrics are controlled by the micrometerEnabled container property, which is true by default.

https://docs.spring.io/spring-kafka/docs/current/reference/html/#micrometer

The metrics will only be captured if Micrometer is on the class path.

If you can't figure it out, provide an MCRE so we can see what is wrong.

huangapple
  • 本文由 发表于 2023年3月9日 19:17:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定