3
votes

I have implemented two cacheManagers. One using caffiene and one using redis. I have exposed them as beans and they are working as expected of them. There isn't any cache endpoint in the list available at /actuator/metrics path either.
I was able to only load /actuator/caches and /actuator/caches/{cacheName} endpoint. These endpoint only show the name and class of the cache being used. I am unable to see any metrics related to them. I am using springboot 2.1.3 and spring-boot-actuator.

 @Bean
    public CacheManager caffeine() {
        CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
        caffeineCacheManager.setCaffeine(caffeineCacheBuilder());
        return caffeineCacheManager;
    }

    private Caffeine<Object, Object> caffeineCacheBuilder() {
        return Caffeine.newBuilder().
                initialCapacity(initialCapacity).
                maximumSize(maxCapacity).
                expireAfterAccess(Duration.parse(ttl)).
                recordStats();
    }
1

1 Answers

1
votes

Turned out @Cacheable makes the cache dynamically at runtime, thus if we want the annotated caches to have metrics, we have to set the cache names explicitly in the cacheManagerBean which inturn makes the cacheManager static.
Or create a custom registryBinder as stated in after upgrade to Spring Boot 2, how to expose cache metrics to prometheus? and call the register method only after the cache is created.