Search in sources :

Example 1 with CacheStatistics

use of org.springframework.boot.actuate.cache.CacheStatistics in project spring-boot by spring-projects.

the class CachePublicMetrics method addMetrics.

private void addMetrics(Collection<Metric<?>> metrics, String cacheName, List<CacheManagerBean> cacheManagerBeans) {
    for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
        CacheManager cacheManager = cacheManagerBean.getCacheManager();
        Cache cache = cacheManager.getCache(cacheName);
        CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
        if (statistics != null) {
            String prefix = cacheName;
            if (cacheManagerBeans.size() > 1) {
                prefix = cacheManagerBean.getBeanName() + "_" + prefix;
            }
            prefix = "cache." + prefix + (prefix.endsWith(".") ? "" : ".");
            metrics.addAll(statistics.toMetrics(prefix));
        }
    }
}
Also used : CacheStatistics(org.springframework.boot.actuate.cache.CacheStatistics) CacheManager(org.springframework.cache.CacheManager) Cache(org.springframework.cache.Cache)

Example 2 with CacheStatistics

use of org.springframework.boot.actuate.cache.CacheStatistics in project spring-boot by spring-projects.

the class CacheStatisticsAutoConfigurationTests method doTestCoreStatistics.

private void doTestCoreStatistics(CacheStatisticsProvider provider, boolean supportSize) {
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(cacheStatistics, (supportSize ? 0L : null), null, null);
    getOrCreate(books, "a", "b", "b", "a", "a", "a");
    CacheStatistics updatedCacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, (supportSize ? 2L : null), 0.66D, 0.33D);
}
Also used : CacheStatistics(org.springframework.boot.actuate.cache.CacheStatistics) Cache(org.springframework.cache.Cache)

Example 3 with CacheStatistics

use of org.springframework.boot.actuate.cache.CacheStatistics in project spring-boot by spring-projects.

the class CacheStatisticsAutoConfigurationTests method noOpCacheStatistics.

@Test
public void noOpCacheStatistics() {
    load(NoOpCacheConfig.class);
    CacheStatisticsProvider provider = this.context.getBean("noOpCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(cacheStatistics, null, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, null, null, null);
}
Also used : CacheStatistics(org.springframework.boot.actuate.cache.CacheStatistics) CacheStatisticsProvider(org.springframework.boot.actuate.cache.CacheStatisticsProvider) Cache(org.springframework.cache.Cache) Test(org.junit.Test)

Example 4 with CacheStatistics

use of org.springframework.boot.actuate.cache.CacheStatistics in project spring-boot by spring-projects.

the class CacheStatisticsAutoConfigurationTests method concurrentMapCacheStatistics.

@Test
public void concurrentMapCacheStatistics() {
    load(ConcurrentMapConfig.class);
    CacheStatisticsProvider provider = this.context.getBean("concurrentMapCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(cacheStatistics, 0L, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider.getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, 2L, null, null);
}
Also used : CacheStatistics(org.springframework.boot.actuate.cache.CacheStatistics) CacheStatisticsProvider(org.springframework.boot.actuate.cache.CacheStatisticsProvider) Cache(org.springframework.cache.Cache) Test(org.junit.Test)

Aggregations

CacheStatistics (org.springframework.boot.actuate.cache.CacheStatistics)4 Cache (org.springframework.cache.Cache)4 Test (org.junit.Test)2 CacheStatisticsProvider (org.springframework.boot.actuate.cache.CacheStatisticsProvider)2 CacheManager (org.springframework.cache.CacheManager)1