I have a Spring Boot 2 application that has caching with Caffeine
cache manager already implemented. Caching is implemented in a standard way with @Cacheable
, @CacheEvict
, @CachePut
annotations.
I migrated the app for using Redis
to have caching distributed between pods.
The problem now is with metrics. Before migration Caffeine
exposed cache metrics like cache_puts_total
, cache_gets_total
, etc. and now there is nothing. Is there something implemented for metrics in RedisCacheManager
? I can not find anything.
2
Answers
Unfortunately as you can see in the Spring Boot documentation: 52. Metrics, Spring Boot does not provide cache statistics for Redis by default:
As another alternative to implementing this yourself, you can use Redisson. This Redis client comes with an integration with Spring that exposes Prometheus metrics. Your metrics will look just like you hint:
You can configure the RedisCacheManager to give the metrics to you. First, you need to implement the CacheStatisticsCollector by adding the necessary types of metrics from the Prometheus. Then this implementation should be added to the RedisCacheWriter, which should be placed in the RedisCacheManager. For instance: