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
ConstructorDescriptionCaffeineStatsCounter
(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 TypeMethodDescriptionvoid
void
recordEviction
(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause) void
recordHits
(int count) void
recordLoadFailure
(long loadTime) void
recordLoadSuccess
(long loadTime) void
recordMisses
(int count) void
registerSizeMetric
(com.github.benmanes.caffeine.cache.Cache<?, ?> cache) Register a gauge for the size of the given cache.com.github.benmanes.caffeine.cache.stats.CacheStats
snapshot()
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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:
recordHits
in interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordMisses
public void recordMisses(int count) - Specified by:
recordMisses
in interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordLoadSuccess
public void recordLoadSuccess(long loadTime) - Specified by:
recordLoadSuccess
in interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordLoadFailure
public void recordLoadFailure(long loadTime) - Specified by:
recordLoadFailure
in interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordEviction
public void recordEviction()- Specified by:
recordEviction
in interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordEviction
public void recordEviction(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause) - Specified by:
recordEviction
in interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
snapshot
public com.github.benmanes.caffeine.cache.stats.CacheStats snapshot()- Specified by:
snapshot
in interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
toString
-