spring-bootprometheusspring-boot-actuatorspring-cachemicrometer

Monitoring spring boot cache metrics with Prometheus


I am trying to use prometheus to monitor some cache metrics from spring-boot. The cache is created with @Cacheable and my configuration is as follows:

management.endpoints:
  web.exposure.include: "*"
  metrics.enabled: true
  prometheus.enabled: true
management.metrics:
  export.prometheus.enabled: true
  cache.instrument: true

My cache is created with a simple @Cacheable('mycache') - I have no other cache code or setup. I'm also NOT using any specific cache provided just the built in one.

I do see my cache in the /actuator/caches/ list, but no detailed in either the /metrics or /prometheus endpoints.

My expectation was that some cache metrics would be published to both the /actuator/metrics and /actuator/prometheus endpoints.

I saw some notes about manually needing to register the cache, but I couldn't get that working either (nor am I sure it really pertains). When attempting to do this the issue is that I cannot autowire in the CacheMetricsRegistrar bean. It's not found.


Solution

  • There isn't a Micrometer binder for the built in hashmap based cache. See https://github.com/micrometer-metrics/micrometer/tree/master/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/cache for the implementation created out of the box.

    Those implementation keep track of their hit/miss counts themselves. Since nothing is tracking the hashmap isn't tracking metrics, there are none available to surface.