Class JCacheMetrics
java.lang.Object
io.micrometer.core.instrument.binder.cache.CacheMeterBinder
io.micrometer.core.instrument.binder.cache.JCacheMetrics
- All Implemented Interfaces:
MeterBinder
@NonNullApi @NonNullFields public class JCacheMetrics extends CacheMeterBinder
Collect metrics on JSR-107 JCache caches, including detailed metrics on manual puts and removals.
See https://github.com/jsr107/demo/blob/master/src/test/java/javax/cache/core/StatisticsExample.java
Note that JSR-107 does not provide any insight into the size or estimated size of the cache, so the size metric of a JCache cache will always report 0.
-
Constructor Summary
Constructors Constructor Description JCacheMetrics(javax.cache.Cache<?,?> cache, java.lang.Iterable<Tag> tags) -
Method Summary
Modifier and Type Method Description protected voidbindImplementationSpecificMetrics(MeterRegistry registry)Bind detailed metrics that are particular to the cache implementation, e.g.protected java.lang.LongevictionCount()protected longhitCount()protected java.lang.LongmissCount()static <K, V, C extends javax.cache.Cache<K, V>>
Cmonitor(MeterRegistry registry, C cache, java.lang.Iterable<Tag> tags)Record metrics on a JCache cache.static <K, V, C extends javax.cache.Cache<K, V>>
Cmonitor(MeterRegistry registry, C cache, java.lang.String... tags)Record metrics on a JCache cache.protected longputCount()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 java.lang.Longsize()MOST cache implementations provide a means of retrieving the number of entries.Methods inherited from class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
bindTo, getTagsWithCacheNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
JCacheMetrics
-
-
Method Details
-
monitor
public static <K, V, C extends javax.cache.Cache<K, V>> C monitor(MeterRegistry registry, C cache, java.lang.String... tags)Record metrics on a JCache cache.- Type Parameters:
C- The cache type.K- The cache key type.V- The cache value 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 instrumented cache, unchanged. The original cache is not wrapped or proxied in any way.
-
monitor
public static <K, V, C extends javax.cache.Cache<K, V>> C monitor(MeterRegistry registry, C cache, java.lang.Iterable<Tag> tags)Record metrics on a JCache cache.- Type Parameters:
C- The cache type.K- The cache key type.V- The cache value type.- Parameters:
registry- The registry to bind metrics to.cache- The cache to instrument.tags- Tags to apply to all recorded metrics.- Returns:
- The instrumented cache, unchanged. The original cache is not wrapped or proxied in any way.
-
size
protected java.lang.Long size()Description copied from class:CacheMeterBinderMOST cache implementations provide a means of retrieving the number of entries. Even if- Specified by:
sizein classCacheMeterBinder- Returns:
- Total number of cache entries. This value may go up or down with puts, removes, and evictions. Returns
nullif the cache implementation does not provide a way to track cache size.
-
hitCount
protected long hitCount()- Specified by:
hitCountin classCacheMeterBinder- Returns:
- Get requests that resulted in a "hit" against an existing cache entry. Monotonically increasing hit count.
-
missCount
protected java.lang.Long missCount()- Specified by:
missCountin classCacheMeterBinder- Returns:
- Get requests that resulted in a "miss", or didn't match an existing cache entry. Monotonically increasing count.
Returns
nullif the cache implementation does not provide a way to track miss count, especially in distributed caches.
-
evictionCount
protected java.lang.Long evictionCount()- Specified by:
evictionCountin classCacheMeterBinder- Returns:
- Total number of entries that have been evicted from the cache. Monotonically increasing eviction count.
Returns
nullif the cache implementation does not support eviction, or does not provide a way to track the eviction count.
-
putCount
protected long putCount()Description copied from class:CacheMeterBinderThe 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. Note that Guava/Caffeine caches don't count manual puts.- Specified by:
putCountin classCacheMeterBinder- Returns:
- Total number of entries added to the cache. Monotonically increasing count.
-
bindImplementationSpecificMetrics
Description copied from class:CacheMeterBinderBind 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.- Specified by:
bindImplementationSpecificMetricsin classCacheMeterBinder- Parameters:
registry- The registry to bind metrics to.
-