Class CacheMeterBinder

  • All Implemented Interfaces:
    MeterBinder
    Direct Known Subclasses:
    CaffeineCacheMetrics, EhCache2Metrics, GuavaCacheMetrics, HazelcastCacheMetrics, JCacheMetrics

    @NonNullApi
    @NonNullFields
    public abstract class CacheMeterBinder
    extends java.lang.Object
    implements MeterBinder
    A common base class for cache metrics that ensures that all caches are instrumented with the same basic set of metrics while allowing for additional detail that is specific to an individual implementation.

    Having this common base set of metrics ensures that you can reason about basic cache performance in a dimensional slice that spans different cache implementations in your application.

    • Constructor Summary

      Constructors 
      Constructor Description
      CacheMeterBinder​(java.lang.Object cache, java.lang.String cacheName, java.lang.Iterable<Tag> tags)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void bindImplementationSpecificMetrics​(MeterRegistry registry)
      Bind detailed metrics that are particular to the cache implementation, e.g.
      void bindTo​(MeterRegistry registry)  
      protected abstract java.lang.Long evictionCount()  
      protected java.lang.Iterable<Tag> getTagsWithCacheName()  
      protected abstract long hitCount()  
      protected abstract java.lang.Long missCount()  
      protected abstract long putCount()
      The put mechanism is unimportant - this count applies to entries added to the cache according to a pre-defined load function such as exists in Guava/Caffeine caches as well as manual puts.
      protected abstract java.lang.Long size()
      MOST cache implementations provide a means of retrieving the number of entries.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CacheMeterBinder

        public CacheMeterBinder​(java.lang.Object cache,
                                java.lang.String cacheName,
                                java.lang.Iterable<Tag> tags)
    • Method Detail

      • size

        @Nullable
        protected abstract java.lang.Long size()
        MOST cache implementations provide a means of retrieving the number of entries. Even if
        Returns:
        Total number of cache entries. This value may go up or down with puts, removes, and evictions. Returns null if the cache implementation does not provide a way to track cache size.
      • hitCount

        protected abstract long hitCount()
        Returns:
        Get requests that resulted in a "hit" against an existing cache entry. Monotonically increasing hit count.
      • missCount

        @Nullable
        protected abstract java.lang.Long missCount()
        Returns:
        Get requests that resulted in a "miss", or didn't match an existing cache entry. Monotonically increasing count. Returns null if the cache implementation does not provide a way to track miss count, especially in distributed caches.
      • evictionCount

        @Nullable
        protected abstract java.lang.Long evictionCount()
        Returns:
        Total number of entries that have been evicted from the cache. Monotonically increasing eviction count. Returns null if the cache implementation does not support eviction, or does not provide a way to track the eviction count.
      • putCount

        protected abstract long putCount()
        The put mechanism is unimportant - this count applies to entries added to the cache according to a pre-defined load function such as exists in Guava/Caffeine caches as well as manual puts.
        Returns:
        Total number of entries added to the cache. Monotonically increasing count.
      • bindImplementationSpecificMetrics

        protected abstract void bindImplementationSpecificMetrics​(MeterRegistry registry)
        Bind detailed metrics that are particular to the cache implementation, e.g. load duration for Caffeine caches, heap and disk size for EhCache caches. These metrics are above and beyond the basic set of metrics that is common to all caches.
        Parameters:
        registry - The registry to bind metrics to.
      • getTagsWithCacheName

        protected java.lang.Iterable<Tag> getTagsWithCacheName()