net.sf.ehcache.statistics.StatisticsGateway Java Examples
The following examples show how to use
net.sf.ehcache.statistics.StatisticsGateway.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EhCacheStatistics.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
/** * Gets the size of heap consumed by items stored in the cache. * * @return Memory size. */ @Override public long getSize() { final StatisticsGateway statistics = cache.getStatistics(); // Store component sizes on each call to avoid recalculating // sizes in other methods that need them if (useBytes) { diskSize = statistics.getLocalDiskSizeInBytes(); heapSize = statistics.getLocalHeapSizeInBytes(); } else { diskSize = cache.getDiskStoreSize(); heapSize = cache.getMemoryStoreSize(); } offHeapSize = statistics.getLocalOffHeapSizeInBytes(); return heapSize; }
Example #2
Source File: EhCacheStatistics.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
/** * Gets the size of heap consumed by items stored in the cache. * * @return Memory size. */ @Override public long getSize() { final StatisticsGateway statistics = cache.getStatistics(); // Store component sizes on each call to avoid recalculating // sizes in other methods that need them if (useBytes) { diskSize = statistics.getLocalDiskSizeInBytes(); heapSize = statistics.getLocalHeapSizeInBytes(); } else { diskSize = cache.getDiskStoreSize(); heapSize = cache.getMemoryStoreSize(); } offHeapSize = statistics.getLocalOffHeapSizeInBytes(); return heapSize; }
Example #3
Source File: EhCache2Metrics.java From micrometer with Apache License 2.0 | 6 votes |
private void commitTransactionMetrics(MeterRegistry registry) { FunctionCounter.builder("cache.xa.commits", stats, StatisticsGateway::xaCommitReadOnlyCount) .tags(getTagsWithCacheName()) .tags("result", "readOnly") .description("Transaction commits that had a read-only result") .register(registry); FunctionCounter.builder("cache.xa.commits", stats, StatisticsGateway::xaCommitExceptionCount) .tags(getTagsWithCacheName()) .tags("result", "exception") .description("Transaction commits that failed") .register(registry); FunctionCounter.builder("cache.xa.commits", stats, StatisticsGateway::xaCommitCommittedCount) .tags(getTagsWithCacheName()) .tags("result", "committed") .description("Transaction commits that failed") .register(registry); }
Example #4
Source File: CacheInformationProvider.java From gocd with Apache License 2.0 | 6 votes |
public Map<String, Object> getCacheRuntimeInformationAsJson(Cache cache) { LinkedHashMap<String, Object> json = new LinkedHashMap<>(); StatisticsGateway statistics = cache.getStatistics(); json.put("Get Time in milliseconds", getStatisticsFrom(statistics.cacheGetOperation())); json.put("Put Time in milliseconds", getStatisticsFrom(statistics.cachePutOperation())); json.put("Remove Time in milliseconds", getStatisticsFrom(statistics.cacheRemoveOperation())); json.put("Cache Size", statistics.getSize()); LinkedHashMap<String, Long> cacheCount = new LinkedHashMap<>(); cacheCount.put("Hits", statistics.cacheHitCount()); cacheCount.put("Miss", statistics.cacheMissCount()); cacheCount.put("Expired", statistics.cacheExpiredCount()); cacheCount.put("Eviction", statistics.cacheEvictedCount()); cacheCount.put("Put", statistics.cachePutCount()); cacheCount.put("Remove", statistics.cacheRemoveCount()); json.put("Cache Counts", cacheCount); json.put("Cache Size (Disk)", statistics.getLocalDiskSize()); json.put("Cache Count (Disk)", statistics.localDiskHitCount()); return json; }
Example #5
Source File: EhCache2Metrics.java From micrometer with Apache License 2.0 | 5 votes |
private void missMetrics(MeterRegistry registry) { FunctionCounter.builder("cache.misses", stats, StatisticsGateway::cacheMissExpiredCount) .tags(getTagsWithCacheName()) .tags("reason", "expired") .description("The number of times cache lookup methods have not returned a value, due to expiry") .register(registry); FunctionCounter.builder("cache.misses", stats, StatisticsGateway::cacheMissNotFoundCount) .tags(getTagsWithCacheName()) .tags("reason", "notFound") .description("The number of times cache lookup methods have not returned a value, because the key was not found") .register(registry); }
Example #6
Source File: EhCache2Metrics.java From micrometer with Apache License 2.0 | 5 votes |
private void rollbackTransactionMetrics(MeterRegistry registry) { FunctionCounter.builder("cache.xa.rollbacks", stats, StatisticsGateway::xaRollbackExceptionCount) .tags(getTagsWithCacheName()) .tags("result", "exception") .description("Transaction rollbacks that failed") .register(registry); FunctionCounter.builder("cache.xa.rollbacks", stats, StatisticsGateway::xaRollbackSuccessCount) .tags(getTagsWithCacheName()) .tags("result", "success") .description("Transaction rollbacks that failed") .register(registry); }
Example #7
Source File: EhCache2Metrics.java From micrometer with Apache License 2.0 | 5 votes |
private void recoveryTransactionMetrics(MeterRegistry registry) { FunctionCounter.builder("cache.xa.recoveries", stats, StatisticsGateway::xaRecoveryNothingCount) .tags(getTagsWithCacheName()) .tags("result", "nothing") .description("Recovery transactions that recovered nothing") .register(registry); FunctionCounter.builder("cache.xa.recoveries", stats, StatisticsGateway::xaRecoveryRecoveredCount) .tags(getTagsWithCacheName()) .tags("result", "success") .description("Successful recovery transaction") .register(registry); }
Example #8
Source File: CacheDirectorImpl.java From yes-cart with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public List<CacheInfoDTO> getCacheInfo() { final Collection<String> cacheNames = cacheManager.getCacheNames(); final List<CacheInfoDTO> rez = new ArrayList<>(cacheNames.size()); for (String cacheName : cacheNames) { final Cache cache = cacheManager.getCache(cacheName); final net.sf.ehcache.Cache nativeCache = (net.sf.ehcache.Cache) cache.getNativeCache(); final CacheConfiguration cacheConfiguration = nativeCache.getCacheConfiguration(); final StatisticsGateway stats = nativeCache.getStatistics(); rez.add( new CacheInfoDTO( nativeCache.getName(), nativeCache.getSize(), stats.getLocalHeapSize(), cacheConfiguration.getMaxEntriesLocalHeap(), cacheConfiguration.isOverflowToDisk(), cacheConfiguration.isEternal(), cacheConfiguration.getTimeToLiveSeconds(), cacheConfiguration.getTimeToIdleSeconds(), cacheConfiguration.getMemoryStoreEvictionPolicy().toString(), stats.getLocalDiskSize(), stats.getCore().get().value(CacheOperationOutcomes.GetOutcome.HIT), stats.getExtended().allMiss().count().value(), stats.getLocalHeapSizeInBytes(), stats.getLocalDiskSizeInBytes(), nativeCache.isDisabled() ) ); } return rez; }
Example #9
Source File: EhCache2MetricsTest.java From micrometer with Apache License 2.0 | 5 votes |
@BeforeAll static void setup() { cacheManager = CacheManager.newInstance(); cacheManager.addCache("testCache"); cache = spy(cacheManager.getCache("testCache")); StatisticsGateway stats = mock(StatisticsGateway.class); // generate non-negative random value to address false-positives int valueBound = 100000; Random random = new Random(); when(stats.getSize()).thenReturn((long) random.nextInt(valueBound)); when(stats.cacheEvictedCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.cacheHitCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.cacheMissCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.cachePutCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.getRemoteSize()).thenReturn((long) random.nextInt(valueBound)); when(stats.cacheRemoveCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.cachePutAddedCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.cachePutUpdatedCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.getLocalOffHeapSizeInBytes()).thenReturn((long) random.nextInt(valueBound)); when(stats.getLocalHeapSizeInBytes()).thenReturn((long) random.nextInt(valueBound)); when(stats.getLocalDiskSizeInBytes()).thenReturn((long) random.nextInt(valueBound)); when(stats.cacheMissExpiredCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.cacheMissNotFoundCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.xaCommitCommittedCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.xaCommitExceptionCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.xaCommitReadOnlyCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.xaRollbackExceptionCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.xaRollbackSuccessCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.xaRecoveryRecoveredCount()).thenReturn((long) random.nextInt(valueBound)); when(stats.xaRecoveryNothingCount()).thenReturn((long) random.nextInt(valueBound)); when(cache.getStatistics()).thenReturn(stats); }
Example #10
Source File: GoCache.java From gocd with Apache License 2.0 | 4 votes |
public StatisticsGateway statistics() { return ehCache.getStatistics(); }
Example #11
Source File: EhCache2MetricsTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test void returnPutCount() { StatisticsGateway stats = cache.getStatistics(); assertThat(metrics.putCount()).isEqualTo(stats.cachePutCount()); }
Example #12
Source File: EhCache2MetricsTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test void returnMissCount() { StatisticsGateway stats = cache.getStatistics(); assertThat(metrics.missCount()).isEqualTo(stats.cacheMissCount()); }
Example #13
Source File: EhCache2MetricsTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test void returnHitCount() { StatisticsGateway stats = cache.getStatistics(); assertThat(metrics.hitCount()).isEqualTo(stats.cacheHitCount()); }
Example #14
Source File: EhCache2MetricsTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test void returnEvictionCount() { StatisticsGateway stats = cache.getStatistics(); assertThat(metrics.evictionCount()).isEqualTo(stats.cacheEvictedCount()); }
Example #15
Source File: EhCache2MetricsTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test void returnCacheSize() { StatisticsGateway stats = cache.getStatistics(); assertThat(metrics.size()).isEqualTo(stats.getSize()); }
Example #16
Source File: EhCache2MetricsTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test void reportMetrics() { MeterRegistry registry = new SimpleMeterRegistry(); metrics.bindTo(registry); verifyCommonCacheMetrics(registry, metrics); StatisticsGateway stats = cache.getStatistics(); Gauge remoteSize = fetch(registry, "cache.remoteSize").gauge(); assertThat(remoteSize.value()).isEqualTo(stats.getRemoteSize()); FunctionCounter cacheRemovals = fetch(registry, "cache.removals").functionCounter(); assertThat(cacheRemovals.count()).isEqualTo(stats.cacheRemoveCount()); String cacheAdded = "cache.puts.added"; FunctionCounter putsAdded = fetch(registry, cacheAdded, Tags.of("result", "added")).functionCounter(); assertThat(putsAdded.count()).isEqualTo(stats.cachePutAddedCount()); FunctionCounter putsUpdated = fetch(registry, cacheAdded, Tags.of("result", "updated")).functionCounter(); assertThat(putsUpdated.count()).isEqualTo(stats.cachePutUpdatedCount()); Gauge offHeapSize = fetch(registry, "cache.local.offheap.size").gauge(); assertThat(offHeapSize.value()).isEqualTo(stats.getLocalOffHeapSizeInBytes()); Gauge heapSize = fetch(registry, "cache.local.heap.size").gauge(); assertThat(heapSize.value()).isEqualTo(stats.getLocalHeapSizeInBytes()); Gauge diskSize = fetch(registry, "cache.local.disk.size").gauge(); assertThat(diskSize.value()).isEqualTo(stats.getLocalDiskSizeInBytes()); // miss metrics String misses = "cache.misses"; FunctionCounter expiredMisses = fetch(registry, misses, Tags.of("reason", "expired")).functionCounter(); assertThat(expiredMisses.count()).isEqualTo(stats.cacheMissExpiredCount()); FunctionCounter notFoundMisses = fetch(registry, misses, Tags.of("reason", "notFound")).functionCounter(); assertThat(notFoundMisses.count()).isEqualTo(stats.cacheMissNotFoundCount()); // commit transaction metrics String xaCommits = "cache.xa.commits"; FunctionCounter readOnlyCommits = fetch(registry, xaCommits, Tags.of("result", "readOnly")).functionCounter(); assertThat(readOnlyCommits.count()).isEqualTo(stats.xaCommitReadOnlyCount()); FunctionCounter exceptionCommits = fetch(registry, xaCommits, Tags.of("result", "exception")).functionCounter(); assertThat(exceptionCommits.count()).isEqualTo(stats.xaCommitExceptionCount()); FunctionCounter committedCommits = fetch(registry, xaCommits, Tags.of("result", "committed")).functionCounter(); assertThat(committedCommits.count()).isEqualTo(stats.xaCommitCommittedCount()); // rollback transaction metrics String xaRollbacks = "cache.xa.rollbacks"; FunctionCounter exceptionRollback = fetch(registry, xaRollbacks, Tags.of("result", "exception")) .functionCounter(); assertThat(exceptionRollback.count()).isEqualTo(stats.xaRollbackExceptionCount()); FunctionCounter successRollback = fetch(registry, xaRollbacks, Tags.of("result", "success")).functionCounter(); assertThat(successRollback.count()).isEqualTo(stats.xaRollbackSuccessCount()); // recovery transaction metrics String xaRecoveries = "cache.xa.recoveries"; FunctionCounter nothingRecovered = fetch(registry, xaRecoveries, Tags.of("result", "nothing")) .functionCounter(); assertThat(nothingRecovered.count()).isEqualTo(stats.xaRecoveryNothingCount()); FunctionCounter successRecoveries = fetch(registry, xaRecoveries, Tags.of("result", "success")) .functionCounter(); assertThat(successRecoveries.count()).isEqualTo(stats.xaRecoveryRecoveredCount()); }
Example #17
Source File: EhCache2Metrics.java From micrometer with Apache License 2.0 | 4 votes |
@Override protected void bindImplementationSpecificMetrics(MeterRegistry registry) { Gauge.builder("cache.remoteSize", stats, StatisticsGateway::getRemoteSize) .tags(getTagsWithCacheName()) .description("The number of entries held remotely in this cache") .register(registry); FunctionCounter.builder("cache.removals", stats, StatisticsGateway::cacheRemoveCount) .tags(getTagsWithCacheName()) .description("Cache removals") .register(registry); FunctionCounter.builder("cache.puts.added", stats, StatisticsGateway::cachePutAddedCount) .tags(getTagsWithCacheName()).tags("result", "added") .description("Cache puts resulting in a new key/value pair") .register(registry); FunctionCounter.builder("cache.puts.added", stats, StatisticsGateway::cachePutUpdatedCount) .tags(getTagsWithCacheName()).tags("result", "updated") .description("Cache puts resulting in an updated value") .register(registry); missMetrics(registry); commitTransactionMetrics(registry); rollbackTransactionMetrics(registry); recoveryTransactionMetrics(registry); Gauge.builder("cache.local.offheap.size", stats, StatisticsGateway::getLocalOffHeapSizeInBytes) .tags(getTagsWithCacheName()) .description("Local off-heap size") .baseUnit(BaseUnits.BYTES) .register(registry); Gauge.builder("cache.local.heap.size", stats, StatisticsGateway::getLocalHeapSizeInBytes) .tags(getTagsWithCacheName()) .description("Local heap size") .baseUnit(BaseUnits.BYTES) .register(registry); Gauge.builder("cache.local.disk.size", stats, StatisticsGateway::getLocalDiskSizeInBytes) .tags(getTagsWithCacheName()) .description("Local disk size") .baseUnit(BaseUnits.BYTES) .register(registry); }