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 java.lang.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:
CaffeineCacheMetrics
-
Constructor Summary
Constructors Constructor Description CaffeineStatsCounter(MeterRegistry registry, java.lang.String cacheName)Constructs an instance for use by a single cache.CaffeineStatsCounter(MeterRegistry registry, java.lang.String cacheName, java.lang.Iterable<Tag> extraTags)Constructs an instance for use by a single cache. -
Method Summary
Modifier and Type Method Description voidrecordEviction()voidrecordEviction(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()java.lang.StringtoString()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
public CaffeineStatsCounter(MeterRegistry registry, java.lang.String cacheName, java.lang.Iterable<Tag> extraTags)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
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-