禁用Spring Boot 3.2的Exemplars支持以解决Prometheus指标采集问题
禁用Spring Boot 3.2的Exemplars支持以兼容低版本Prometheus
Spring Boot 3.2新增了Exemplars支持,但该特性要求Prometheus版本不低于2.43.0。如果你的Prometheus版本较低,升级Spring Boot后会出现类似 metric name web_client_requests_seconds_count does not support exemplars 的报错,导致指标采集失败。在完成Prometheus升级前,可以通过以下两种方式禁用Exemplars支持:
方法一:通过配置文件禁用
在你的application.properties或application.yml中添加以下配置,全局关闭Prometheus exporter的Exemplars功能:
application.properties
management.metrics.export.prometheus.exemplars.enabled=false
application.yml
management: metrics: export: prometheus: exemplars: enabled: false
方法二:通过Java配置类禁用
创建自定义配置类,通过PrometheusMeterRegistryCustomizer来关闭Exemplars支持:
import io.micrometer.prometheus.PrometheusMeterRegistry; import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMeterRegistryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class PrometheusExemplarConfig { @Bean public PrometheusMeterRegistryCustomizer prometheusExemplarDisabler() { return registry -> registry.setExemplarsEnabled(false); } }
以上两种方式均可让低版本Prometheus正常采集应用指标,待完成Prometheus升级至2.43.0及以上版本后,可重新启用Exemplars支持。
内容的提问来源于stack exchange,提问作者Piotr Kozlowski
相关产品推荐
相关产品推荐

