[英]How to expose cache statistics for Guava Cache
I'm using spring boot 1.5 and I cannot expose guava cache statistics in /prometheus
endpoint. 我正在使用spring boot 1.5,我无法在
/prometheus
端点中公开guava缓存统计信息。 Eventually I can expose it as JMX but then I dont know how to wire these things up. 最终我可以将它暴露为JMX,但后来我不知道如何连接这些东西。 Is there some easier way how to do it?
有一些更简单的方法怎么做?
I am creating the cache with cache builder as following: 我正在使用缓存构建器创建缓存,如下所示:
@Bean
@Primary
public CacheManager cacheManager() {
final GuavaCacheManager cacheManager = new GuavaCacheManager();
final CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder()
.maximumSize(5000)
.recordStats()
.expireAfterWrite(1, TimeUnit.HOURS);
cacheManager.setCacheBuilder(cacheBuilder);
cacheManager.setCacheNames(Lists.newArrayList("TEST_CACHE"));
return cacheManager;
}
I am using .recordStats()
method as well. 我
.recordStats()
使用.recordStats()
方法。
You can monitor the Guava chache metrics by using the GuavaCacheMetrics binder 您可以使用GuavaCacheMetrics绑定器监视Guava chache指标
GuavaCacheBuilder.monitor(meterRegistry, aCache, "myCacheName")
Notice since you are using a cache builder with the CacheManager
you would need to make that monitor
call for each individual cache. 请注意,由于您正在使用具有
CacheManager
的缓存构建器,因此您需要为每个缓存调用该monitor
。
There are other ways to approach this, and the CacheManager
is automatically instrumented in SpringBot 2.x I believe. 还有其他方法可以解决这个问题,我相信在SpringBot 2.x中自动检测
CacheManager
。 So upgrading will give you a simpler integration. 因此升级将为您提供更简单的集成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.