Using Spring Boot 2.5.7, Micrometer 1.7.6, Ehcache 3.9.7, and have spring-boot-starter-actuator
on the classpath. I'm building a batch application (not a web app, no exposed actuator APIs). I have an ehcache.xml
configured to enable statistics:
<eh:service>
<jsr107:defaults enable-management="true" enable-statistics="true"/>
</eh:service>
<eh:cache alias="myCache" uses-template="default">
<eh:key-type>java.lang.String</eh:key-type>
<eh:value-type>java.lang.String</eh:value-type>
<eh:listeners>
<eh:listener>
<eh:class>com.company.package.MyListener</eh:class>
<!-- more event config ... -->
</eh:listener>
</eh:listeners>
</eh:cache>
I would like to code the listener to periodically write cache statistics to a log. Pseudocode would look something like:
@Autowired
CacheManager mgr;
mgr.getCacheNames().forEach( cacheName -> {
writeCacheStats(cacheName);
});
void writeCacheStats(String cacheName) {
// get statistics for cacheName from Micrometer or Boot... HOW?
// write statistics to log
}
I have combed through Spring Boot Actuator and Micrometer docs plus several blog posts and cannot figure out how to do this. Most of the docs seem to assume one is monitoring via APIs, which is not what I need. It seems like a basic use case so I suspect I'm missing something obvious. I'm hoping someone can point me in the right direction.