【问题标题】:Spring boot micrometer register cache metricsSpring Boot 千分尺寄存器缓存指标
【发布时间】:2020-03-15 22:04:37
【问题描述】:

我在为应用程序的 2 个实例创建指标时遇到问题。 我使用

为 hazelcast 缓存指标创建了指标
 HazelcastCacheMetrics.monitor(prometheusMeterRegistry, (IMap<?, ?>) cache.getNativeCache());

当我运行 1 个应用程序实例时一切正常,但当我运行 2 个实例时出现错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcastCacheMetricConfig': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named 'cache_size' containing tag keys [cache, cacheManager, name]. The meter you are attempting to register has keys [cache].

或者当我将注册的指标更改为

@Autowired
private CacheMetricsRegistrar cacheMetricsRegistrar;

cacheMetricsRegistrar.bindCacheToRegistry(cache, Tag.of("instance", podName));

我有这个错误

 Error creating bean with name 'hazelcastCacheMetricConfig': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named 'cache_size' containing tag keys [cache, cacheManager, name]. The meter you are attempting to register has keys [cache, instance, name].

感谢您帮助解决此问题

【问题讨论】:

    标签: spring spring-boot prometheus metrics


    【解决方案1】:

    您好,使用 MeterRegistryCustomizer 代替 HazelcastCacheMetrics

    导入 io.micrometer.core.instrument.MeterRegistry; 导入 org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;

    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> registry.config().commonTags("application", "MYAPPNAME");
    }
    

    【讨论】:

    • 感谢您的帮助,但是当我将 appName 添加到标签中时,我仍然有错误。有问题更新
    • 你是从 spring props 添加 appName 吗?还是奇怪的编码?
    • 来自环境属性
    • 尝试这样实现,private void bindCacheToRegistry(String beanName, Cache cache) { Tag cacheManagerTag = Tag.of("cacheManager", getCacheManagerName(beanName)); this.cacheMetricsRegistrar.bindCacheToRegistry(cache, cacheManagerTag); } github.com/spring-projects/spring-boot/blob/master/…
    猜你喜欢
    • 1970-01-01
    • 2019-04-10
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 2020-02-17
    • 2022-06-22
    相关资源
    最近更新 更多