I'm using spring boot 1.5 and I cannot expose guava cache statistics in /prometheus
endpoint. Eventually I can expose it as JMX but then I dont know how to wire these things up. 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.
You can monitor the Guava chache metrics by using the GuavaCacheMetrics binder
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.
There are other ways to approach this, and the CacheManager
is automatically instrumented in SpringBot 2.x I believe. So upgrading will give you a simpler integration.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.