Class GuavaCacheMetrics<K,V,C extends com.google.common.cache.Cache<K,V>>
java.lang.Object
io.micrometer.core.instrument.binder.cache.CacheMeterBinder<C>
io.micrometer.core.instrument.binder.cache.GuavaCacheMetrics<K,V,C>
- All Implemented Interfaces:
MeterBinder
@NonNullApi
@NonNullFields
public class GuavaCacheMetrics<K,V,C extends com.google.common.cache.Cache<K,V>>
extends CacheMeterBinder<C>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Bind detailed metrics that are particular to the cache implementation, e.g.protected Long
protected long
hitCount()
protected Long
static <K,
V, C extends com.google.common.cache.Cache<K, V>>
Cmonitor
(MeterRegistry registry, C cache, String cacheName, Iterable<Tag> tags) Record metrics on a Guava cache.static <K,
V, C extends com.google.common.cache.Cache<K, V>>
Cmonitor
(MeterRegistry registry, C cache, String cacheName, String... tags) Record metrics on a Guava cache.protected 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 Long
size()
MOST cache implementations provide a means of retrieving the number of entries.Methods inherited from class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
bindTo, getCache, getTagsWithCacheName
-
Constructor Details
-
GuavaCacheMetrics
-
-
Method Details
-
monitor
public static <K,V, C monitorC extends com.google.common.cache.Cache<K, V>> (MeterRegistry registry, C cache, String cacheName, String... tags) Record metrics on a Guava cache. You must callCacheBuilder.recordStats()
prior to building the cache for metrics to be recorded.- Type Parameters:
K
- Cache key type.V
- Cache value type.C
- The cache type.- Parameters:
registry
- The registry to bind metrics to.cache
- The cache to instrument.cacheName
- Will be used to tag metrics with "cache".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.
- See Also:
-
monitor
public static <K,V, C monitorC extends com.google.common.cache.Cache<K, V>> (MeterRegistry registry, C cache, String cacheName, Iterable<Tag> tags) Record metrics on a Guava cache. You must callCacheBuilder.recordStats()
prior to building the cache for metrics to be recorded.- Type Parameters:
K
- Cache key type.V
- Cache value type.C
- The cache type.- Parameters:
registry
- The registry to bind metrics to.cache
- The cache to instrument.cacheName
- The name prefix of the metrics.tags
- Tags to apply to all recorded metrics.- Returns:
- The instrumented cache, unchanged. The original cache is not wrapped or proxied in any way.
- See Also:
-
size
Description copied from class:CacheMeterBinder
MOST cache implementations provide a means of retrieving the number of entries. Even if- Specified by:
size
in classCacheMeterBinder<C extends com.google.common.cache.Cache<K,
V>> - 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 long hitCount()- Specified by:
hitCount
in classCacheMeterBinder<C extends com.google.common.cache.Cache<K,
V>> - Returns:
- Get requests that resulted in a "hit" against an existing cache entry. Monotonically increasing hit count.
-
missCount
- Specified by:
missCount
in classCacheMeterBinder<C extends com.google.common.cache.Cache<K,
V>> - 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
- Specified by:
evictionCount
in classCacheMeterBinder<C extends com.google.common.cache.Cache<K,
V>> - 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 long putCount()Description copied from class:CacheMeterBinder
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. Note that Guava/Caffeine caches don't count manual puts.- Specified by:
putCount
in classCacheMeterBinder<C extends com.google.common.cache.Cache<K,
V>> - Returns:
- Total number of entries added to the cache. Monotonically increasing count.
-
bindImplementationSpecificMetrics
Description copied from class:CacheMeterBinder
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.- Specified by:
bindImplementationSpecificMetrics
in classCacheMeterBinder<C extends com.google.common.cache.Cache<K,
V>> - Parameters:
registry
- The registry to bind metrics to.
-