Class EhcacheCacheMetrics

java.lang.Object
io.micrometer.core.instrument.binder.cache.CacheMeterBinder
com.broadleafcommerce.common.extension.cache.ehcache.EhcacheCacheMetrics
All Implemented Interfaces:
io.micrometer.core.instrument.binder.MeterBinder

public class EhcacheCacheMetrics extends io.micrometer.core.instrument.binder.cache.CacheMeterBinder
A helper class for monitoring and exposing Ehcache 3 cache metrics through Micrometer.

This implementation utilizes a background thread to refresh the cache statistics (e.g., hit/miss counts, size, and offheap weight) upon a scrape request. By offloading these calculations we prevent blocking the main request threads during Micrometer scrapes.

If a refresh is already in progress, additional scrape requests will use the currently available metrics and will not spawn additional tasks.

This binder exposes cache.offheap.used and cache.offheap.bytes gauges to accurately report the total off-heap memory footprint of the cache region.

  • Constructor Details

    • EhcacheCacheMetrics

      public EhcacheCacheMetrics(ExecutorService refreshExecutor, javax.cache.Cache<?,?> cache, String name, Iterable<io.micrometer.core.instrument.Tag> tags)
  • Method Details

    • monitor

      public static EhcacheCacheMetrics monitor(io.micrometer.core.instrument.MeterRegistry registry, ExecutorService refreshExecutor, javax.cache.Cache<?,?> cache, String name, String... tags)
    • size

      protected Long size()
      Specified by:
      size in class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
    • hitCount

      protected long hitCount()
      Specified by:
      hitCount in class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
    • missCount

      protected Long missCount()
      Specified by:
      missCount in class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
    • evictionCount

      protected Long evictionCount()
      Specified by:
      evictionCount in class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
    • putCount

      protected long putCount()
      Specified by:
      putCount in class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
    • bindImplementationSpecificMetrics

      protected void bindImplementationSpecificMetrics(io.micrometer.core.instrument.MeterRegistry registry)
      Specified by:
      bindImplementationSpecificMetrics in class io.micrometer.core.instrument.binder.cache.CacheMeterBinder