@Test public void cacheExposesMetricsForHitMissAndEviction() throws Exception { Cache<String, String> cache = CacheBuilder.newBuilder().maximumSize(2).recordStats().build(); CollectorRegistry registry = new CollectorRegistry(); CacheMetricsCollector collector = new CacheMetricsCollector().register(registry); collector.addCache("users", cache); cache.getIfPresent("user1"); cache.getIfPresent("user1"); cache.put("user1", "First User"); cache.getIfPresent("user1"); cache.put("user2", "Second User"); cache.put("user3", "Third User"); cache.put("user4", "Fourth User"); assertMetric(registry, "guava_cache_hit_total", "users", 1.0); assertMetric(registry, "guava_cache_miss_total", "users", 2.0); assertMetric(registry, "guava_cache_requests_total", "users", 3.0); assertMetric(registry, "guava_cache_eviction_total", "users", 2.0); }
public void addCache(String cacheName, Cache cache) { children.put(cacheName, cache); }
CacheMetricsCollector extends Collector { public void addCache(String cacheName, Cache cache) { children.put(cacheName, cache); } }
CacheMetricsCollector extends Collector { public void addCache(String cacheName, Cache cache) { children.put(cacheName, cache); }  }
CacheMetricsCollector extends Collector { public void addCache(String cacheName, Cache cache) { children.put(cacheName, cache); }  void addCache(String cacheName, Cache cache); Cache removeCache(String cacheName); void clear(); @Override List<MetricFamilySamples> collect(); }
CacheMetricsCollector extends Collector { public void addCache(String cacheName, Cache cache) { children.put(cacheName, cache); }  void addCache(String cacheName, Cache cache); Cache removeCache(String cacheName); void clear(); @Override List<MetricFamilySamples> collect();  }