Spring Boot 微米寄存器缓存度量

gfttwv5a  于 2024-01-05  发布在  Spring
关注(0)|答案(1)|浏览(184)

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

  1. HazelcastCacheMetrics.monitor(prometheusMeterRegistry, (IMap<?, ?>) cache.getNativeCache());

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

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


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

  1. @Autowired
  2. private CacheMetricsRegistrar cacheMetricsRegistrar;
  3. cacheMetricsRegistrar.bindCacheToRegistry(cache, Tag.of("instance", podName));


我有这个错误

  1. 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缓存

  1. import io.micrometer.core.instrument.MeterRegistry;
  2. import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
  3. @Bean
  4. MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
  5. return registry -> registry.config().commonTags("application", "MYAPPNAME");
  6. }

字符串

相关问题