@NonNullApi @NonNullFields public class CaffeineCacheMetrics extends CacheMeterBinder
Note that `recordStats()` is required to gather non-zero statistics:
Cache<String, String> cache = Caffeine.newBuilder().recordStats().build();
CaffeineCacheMetrics.monitor(registry, cache, "mycache", "region", "test");
| Constructor and Description |
|---|
CaffeineCacheMetrics(com.github.benmanes.caffeine.cache.Cache<?,?> cache,
java.lang.String cacheName,
java.lang.Iterable<Tag> tags)
Creates a new
CaffeineCacheMetrics instance. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
bindImplementationSpecificMetrics(MeterRegistry registry)
Bind detailed metrics that are particular to the cache implementation, e.g.
|
protected java.lang.Long |
evictionCount() |
protected long |
hitCount() |
protected long |
missCount() |
static <C extends com.github.benmanes.caffeine.cache.AsyncLoadingCache> |
monitor(MeterRegistry registry,
C cache,
java.lang.String cacheName,
java.lang.Iterable<Tag> tags)
Record metrics on a Caffeine cache.
|
static <C extends com.github.benmanes.caffeine.cache.Cache> |
monitor(MeterRegistry registry,
C cache,
java.lang.String cacheName,
java.lang.Iterable<Tag> tags)
Record metrics on a Caffeine cache.
|
static <C extends com.github.benmanes.caffeine.cache.AsyncLoadingCache> |
monitor(MeterRegistry registry,
C cache,
java.lang.String cacheName,
java.lang.String... tags)
Record metrics on a Caffeine cache.
|
static <C extends com.github.benmanes.caffeine.cache.Cache> |
monitor(MeterRegistry registry,
C cache,
java.lang.String cacheName,
java.lang.String... tags)
Record metrics on a Caffeine 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 java.lang.Long |
size()
MOST cache implementations provide a means of retrieving the number of entries.
|
bindTo, getTagsWithCacheNamepublic CaffeineCacheMetrics(com.github.benmanes.caffeine.cache.Cache<?,?> cache,
java.lang.String cacheName,
java.lang.Iterable<Tag> tags)
CaffeineCacheMetrics instance.cache - The cache to be instrumented. You must call Caffeine.recordStats() prior to building the cache
for metrics to be recorded.cacheName - Will be used to tag metrics with "cache".tags - tags to apply to all recorded metrics.public static <C extends com.github.benmanes.caffeine.cache.Cache> C monitor(MeterRegistry registry, C cache, java.lang.String cacheName, java.lang.String... tags)
Caffeine.recordStats() prior to building the cache
for metrics to be recorded.C - The cache type.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.public static <C extends com.github.benmanes.caffeine.cache.Cache> C monitor(MeterRegistry registry, C cache, java.lang.String cacheName, java.lang.Iterable<Tag> tags)
Caffeine.recordStats() prior to building the cache
for metrics to be recorded.C - The cache type.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.CacheStatspublic static <C extends com.github.benmanes.caffeine.cache.AsyncLoadingCache> C monitor(MeterRegistry registry, C cache, java.lang.String cacheName, java.lang.String... tags)
Caffeine.recordStats() prior to building the cache
for metrics to be recorded.C - The cache type.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.public static <C extends com.github.benmanes.caffeine.cache.AsyncLoadingCache> C monitor(MeterRegistry registry, C cache, java.lang.String cacheName, java.lang.Iterable<Tag> tags)
Caffeine.recordStats() prior to building the cache
for metrics to be recorded.C - The cache type.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.CacheStatsprotected java.lang.Long size()
CacheMeterBindersize in class CacheMeterBindernull if the cache implementation does not provide a way to track cache size.protected long hitCount()
hitCount in class CacheMeterBinderprotected long missCount()
missCount in class CacheMeterBinderprotected java.lang.Long evictionCount()
evictionCount in class CacheMeterBindernull if the cache implementation does not support eviction, or does not provide a way to track
the eviction count.protected long putCount()
CacheMeterBinderputCount in class CacheMeterBinderprotected void bindImplementationSpecificMetrics(MeterRegistry registry)
CacheMeterBinderbindImplementationSpecificMetrics in class CacheMeterBinderregistry - The registry to bind metrics to.