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; }
System.out.println(testCache.get("1") == null); System.out.println(testCache.getSize()); System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes()); System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M"); System.out.println(testCache.get("2") == null); System.out.println(testCache.getSize()); System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes()); System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M"); System.out.println(testCache.get("3") == null); System.out.println(testCache.getSize()); System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes()); System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getNumberOfElementsOnDisk(java.lang.String) */ public int getNumberOfElementsOnDisk(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { return (int) cache.getStatistics().getLocalDiskSize(); } else { return -1; } }
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getNumberOfElementsInMemory(java.lang.String) */ public int getNumberOfElementsInMemory(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { return (int) cache.getStatistics().getLocalHeapSize(); } else { return -1; } }
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getNumberOfElementsOffHeap(java.lang.String) */ public int getNumberOfElementsOffHeap(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { return (int) cache.getStatistics().getLocalOffHeapSize(); } else { return -1; } }
/** * Gets the size of the off-heap store for this cache. * * @return the size of the off-heap store in bytes * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE} */ @Deprecated public final long calculateOffHeapSize() throws IllegalStateException, CacheException { checkStatus(); return getStatistics().getLocalOffHeapSizeInBytes(); }
/** * Gets the size of the on-disk store for this cache * * @return the size of the on-disk store in bytes * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE} */ @Deprecated public final long calculateOnDiskSize() throws IllegalStateException, CacheException { checkStatus(); return getStatistics().getLocalDiskSizeInBytes(); }
/** * Returns the number of elements in the off-heap store. * * @return the number of elements in the off-heap store * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE} */ @Deprecated public long getOffHeapStoreSize() throws IllegalStateException { checkStatus(); return getStatistics().getLocalOffHeapSize(); }
/** * Returns the number of elements in the memory store. * * @return the number of elements in the memory store * @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE} */ @Deprecated public final long getMemoryStoreSize() throws IllegalStateException { checkStatus(); return getStatistics().getLocalHeapSize(); }
/** * {@inheritDoc} */ public long getCacheMissCount() { long count = 0; for (String name : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(name); if (cache != null) { count += cache.getStatistics().cacheMissCount(); } } return count; }
/** * {@inheritDoc} */ public long getCachePutCount() { long count = 0; for (String name : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(name); if (cache != null) { count += cache.getStatistics().cachePutCount(); } } return count; }
public long getCacheMisses() { Cache cache = manager.getCache(ehcacheConf.getPredefinedCacheName()); return cache.getStatistics().getCacheMisses(); }
/** * {@inheritDoc} */ public long getCacheHitCount() { long count = 0; for (String name : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(name); if (cache != null) { count += cache.getStatistics().cacheHitCount(); } } return count; }
public long getCacheHits() { Cache cache = manager.getCache(ehcacheConf.getPredefinedCacheName()); return cache.getStatistics().getCacheHits(); }
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getMaxGetTimeMillis(java.lang.String) */ public long getMaxGetTimeMillis(String cacheName) { Cache cache = cacheManager.getCache(cacheName); if (cache != null) { return TimeUnit.MILLISECONDS.convert(cache.getStatistics().cacheGetOperation().latency().maximum().value().longValue(), TimeUnit.NANOSECONDS); } else { return 0; } }
/** * {@inheritDoc} * * @see net.sf.ehcache.hibernate.management.api.EhcacheStats#getMinGetTimeMillis(java.lang.String) */ public long getMinGetTimeMillis(String cacheName) { Cache cache = cacheManager.getCache(cacheName); if (cache != null) { return TimeUnit.MILLISECONDS.convert(cache.getStatistics().cacheGetOperation().latency().minimum().value().longValue(), TimeUnit.NANOSECONDS); } else { return 0; } }
/** * {@inheritDoc} */ public long getMaxGetTimeMillis() { long rv = 0; for (String cacheName : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(cacheName); if (cache != null) { rv = Math.max(rv, TimeUnit.MILLISECONDS.convert(cache.getStatistics().cacheSearchOperation().latency().maximum().value().longValue(), TimeUnit.NANOSECONDS)); } } return rv; }
/** * {@inheritDoc} */ public long getCachePutSample() { long count = 0; for (String name : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(name); if (cache != null) { count += cache.getStatistics().cachePutOperation().rate().value().longValue(); } } return count; }
/** * {@inheritDoc} */ public long getCacheMissSample() { long count = 0; for (String name : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(name); if (cache != null) { count += cache.getStatistics().cacheMissOperation().rate().value().longValue(); } } return count; }
/** * {@inheritDoc} */ public long getCacheHitSample() { long count = 0; for (String name : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(name); if (cache != null) { count += cache.getStatistics().cacheHitOperation().rate().value().longValue(); } } return count; }