Spring Boot 微米寄存器缓存度量

gfttwv5a  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(60)

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

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].


谢谢你帮我解决这个问题

f8rj6qna

f8rj6qna1#

Hi使用MeterRegistryCustomizer而不是Hazelcast缓存

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

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

字符串

相关问题