Class Cache2kCacheMetrics

  • All Implemented Interfaces:
    io.micrometer.core.instrument.binder.MeterBinder

    public class Cache2kCacheMetrics
    extends io.micrometer.core.instrument.binder.cache.CacheMeterBinder
    Micrometer support for cache2k. Metrics will be bound automatically upon cache creation if enabled by the configuration. Alternatively, metrics can be bound to a registry programmatically via monitor(MeterRegistry, Cache, String...).
    Author:
    Jens Wilke
    • Constructor Detail

      • Cache2kCacheMetrics

        public Cache2kCacheMetrics​(org.cache2k.Cache<?,​?> cache,
                                   Iterable<io.micrometer.core.instrument.Tag> tags)
        Creates a new Cache2kCacheMetrics instance.
        Parameters:
        cache - The cache to be instrumented.
        tags - tags to apply to all recorded metrics.
    • Method Detail

      • monitor

        public static <C extends org.cache2k.Cache> C monitor​(io.micrometer.core.instrument.MeterRegistry registry,
                                                              C cache,
                                                              String... tags)
        Record metrics for a cache2k cache.
        Type Parameters:
        C - The cache type.
        Parameters:
        registry - The registry to bind metrics to.
        cache - The cache to instrument.
        tags - Tags to apply to all recorded metrics. Must be an even number of arguments representing key/value pairs of tags.
        Returns:
        the cache as passed in.
      • monitor

        public static <C extends org.cache2k.Cache> C monitor​(io.micrometer.core.instrument.MeterRegistry registry,
                                                              C cache,
                                                              Iterable<io.micrometer.core.instrument.Tag> tags)
        Record metrics for a cache2k cache.
        Type Parameters:
        C - The cache type.
        Parameters:
        registry - The registry to bind metrics to.
        cache - The cache to instrument.
        tags - Tags to apply to all recorded metrics.
        Returns:
        the cache as passed in.
      • 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()
        Sum up everything which removes an entry no matter the cause. This is probably most similar to the behavior of other caches.

        TODO: have separate metric for expired entries

        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)
        Returns additional metrics similar to Caffeine and Guava.

        TODO: loads/refresh, evicted/expired

        Specified by:
        bindImplementationSpecificMetrics in class io.micrometer.core.instrument.binder.cache.CacheMeterBinder