Class CaffeineStatsCounter
java.lang.Object
io.micrometer.core.instrument.binder.cache.CaffeineStatsCounter
- All Implemented Interfaces:
com.github.benmanes.caffeine.cache.stats.StatsCounter
@NonNullApi
@NonNullFields
public final class CaffeineStatsCounter
extends Object
implements com.github.benmanes.caffeine.cache.stats.StatsCounter
A
StatsCounter instrumented with Micrometer. This will provide more detailed
metrics than using CaffeineCacheMetrics.
Note that this doesn't instrument the cache's size by default. Use
registerSizeMetric(Cache) to do so after the cache has been built.
Use Caffeine.recordStats() to supply this
class to the cache builder:
MeterRegistry registry = ...;
Cache<Key, Graph> graphs = Caffeine.newBuilder()
.maximumSize(10_000)
.recordStats(() -> new CaffeineStatsCounter(registry, "graphs"))
.build();
- Since:
- 1.7.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCaffeineStatsCounter(MeterRegistry registry, String cacheName) Constructs an instance for use by a single cache.CaffeineStatsCounter(MeterRegistry registry, String cacheName, Iterable<Tag> extraTags) Constructs an instance for use by a single cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidrecordEviction(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause) voidrecordHits(int count) voidrecordLoadFailure(long loadTime) voidrecordLoadSuccess(long loadTime) voidrecordMisses(int count) voidregisterSizeMetric(com.github.benmanes.caffeine.cache.Cache<?, ?> cache) Register a gauge for the size of the given cache.com.github.benmanes.caffeine.cache.stats.CacheStatssnapshot()toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.github.benmanes.caffeine.cache.stats.StatsCounter
recordEviction
-
Constructor Details
-
CaffeineStatsCounter
Constructs an instance for use by a single cache.- Parameters:
registry- the registry of metric instancescacheName- will be used to tag metrics with "cache".
-
CaffeineStatsCounter
Constructs an instance for use by a single cache.- Parameters:
registry- the registry of metric instancescacheName- will be used to tag metrics with "cache".extraTags- tags to apply to all recorded metrics.
-
-
Method Details
-
registerSizeMetric
public void registerSizeMetric(com.github.benmanes.caffeine.cache.Cache<?, ?> cache) Register a gauge for the size of the given cache.- Parameters:
cache- cache to register a gauge for its size
-
recordHits
public void recordHits(int count) - Specified by:
recordHitsin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordMisses
public void recordMisses(int count) - Specified by:
recordMissesin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordLoadSuccess
public void recordLoadSuccess(long loadTime) - Specified by:
recordLoadSuccessin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordLoadFailure
public void recordLoadFailure(long loadTime) - Specified by:
recordLoadFailurein interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordEviction
public void recordEviction()- Specified by:
recordEvictionin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordEviction
public void recordEviction(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause) - Specified by:
recordEvictionin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
snapshot
public com.github.benmanes.caffeine.cache.stats.CacheStats snapshot()- Specified by:
snapshotin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
toString
-