Package io.prometheus.client.guava.cache
Class CacheMetricsCollector
java.lang.Object
io.prometheus.client.Collector
io.prometheus.client.guava.cache.CacheMetricsCollector
Collect metrics from Guava's com.google.common.cache.Cache.
// Note that `recordStats()` is required to gather non-zero statistics
Cache<String, String> cache = CacheBuilder.newBuilder().recordStats().build();
CacheMetricsCollector cacheMetrics = new CacheMetricsCollector().register();
cacheMetrics.addCache("mycache", cache);
Exposed metrics are labeled with the provided cache name.
With the example above, sample metric names would be:
guava_cache_hit_total{cache="mycache"} 10.0 guava_cache_miss_total{cache="mycache"} 3.0 guava_cache_requests_total{cache="mycache"} 13.0 guava_cache_eviction_total{cache="mycache"} 1.0 guava_cache_size{cache="mycache"} 5.0Additionally if the cache includes a loader, the following metrics would be provided:
guava_cache_load_failure_total{cache="mycache"} 2.0 guava_cache_loads_total{cache="mycache"} 7.0 guava_cache_load_duration_seconds_count{cache="mycache"} 7.0 guava_cache_load_duration_seconds_sum{cache="mycache"} 0.0034
-
Nested Class Summary
Nested classes/interfaces inherited from class io.prometheus.client.Collector
Collector.Describable, Collector.MetricFamilySamples, Collector.Type
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentMap
<String, com.google.common.cache.Cache> Fields inherited from class io.prometheus.client.Collector
MILLISECONDS_PER_SECOND, NANOSECONDS_PER_SECOND
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add or replace the cache with the given name.void
clear()
Remove all caches.collect()
Return all of the metrics of this Collector.com.google.common.cache.Cache
removeCache
(String cacheName) Remove the cache with the given name.Methods inherited from class io.prometheus.client.Collector
checkMetricLabelName, checkMetricName, doubleToGoString, register, register, sanitizeMetricName
-
Field Details
-
children
-
-
Constructor Details
-
CacheMetricsCollector
public CacheMetricsCollector()
-
-
Method Details
-
addCache
Add or replace the cache with the given name.Any references any previous cache with this name is invalidated.
- Parameters:
cacheName
- The name of the cache, will be the metrics label valuecache
- The cache being monitored
-
removeCache
Remove the cache with the given name.Any references to the cache are invalidated.
- Parameters:
cacheName
- cache to be removed
-
clear
public void clear()Remove all caches.Any references to all caches are invalidated.
-
collect
Description copied from class:Collector
Return all of the metrics of this Collector.
-