Refine search
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; }
@Override public Long getValue() { return cache.getStatistics().getLocalHeapSize(); } });
CacheManager cacheManager = CacheManager.create(conf); new Cache(new CacheConfiguration("test", 0).// cacheManager.addCache(testCache); testCache.put(new Element("1", blob)); 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"); cacheManager.shutdown();
/** * {@inheritDoc} */ public double getCacheHitPercentage() { long hits = statistics.cacheHitCount(); long misses = statistics.cacheMissCount(); long total = hits + misses; return getPercentage(hits, total); }
/** * {@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 getCacheHitCount() { long count = 0; for (String name : cacheManager.getCacheNames()) { Cache cache = cacheManager.getCache(name); if (cache != null) { count += cache.getStatistics().cacheHitCount(); } } 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; }
/** * {@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#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; } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String[] cacheNames = cacheManager.getCacheNames(); Cache cache = cacheManager.getCache(name); StatisticsGateway statisticsGateway = cache.getStatistics(); cacheStats.put("CacheSize", statisticsGateway.getSize()); cacheStats.put("HitCount", statisticsGateway.cacheHitCount()); cacheStats.put("MissCount", statisticsGateway.cacheMissCount()); cacheStats.put("LocalHeapSize", statisticsGateway.getLocalHeapSize()); cacheStats.put("LocalHeapHitCount", statisticsGateway.localHeapHitCount()); cacheStats.put("LocalHeapMissCount", statisticsGateway.localHeapMissCount()); cacheStats.put("LocalDiskHitCount", statisticsGateway.localDiskHitCount()); cacheStats.put("LocalDiskMissCount", statisticsGateway.localDiskMissCount());
final String prefix = name(cache.getClass(), cache.getName()); registry.register(name(prefix, "hits"), (Gauge<Long>) () -> cache.getStatistics().cacheHitCount()); (Gauge<Long>) () -> cache.getStatistics().localHeapHitCount()); (Gauge<Long>) () -> cache.getStatistics().localOffHeapHitCount()); (Gauge<Long>) () -> cache.getStatistics().localDiskHitCount()); (Gauge<Long>) () -> cache.getStatistics().cacheMissCount()); (Gauge<Long>) () -> cache.getStatistics().localHeapMissCount()); (Gauge<Long>) () -> cache.getStatistics().localOffHeapMissCount()); (Gauge<Long>) () -> cache.getStatistics().localDiskMissCount()); (Gauge<Long>) () -> cache.getStatistics().getSize()); (Gauge<Long>) () -> cache.getStatistics().getLocalHeapSize()); (Gauge<Long>) () -> cache.getStatistics().getLocalOffHeapSize()); (Gauge<Long>) () -> cache.getStatistics().getLocalDiskSize()); (Gauge<Double>) () -> cache.getStatistics().cacheGetOperation().latency().average().value()); (Gauge<Double>) () -> cache.getStatistics().cacheSearchOperation().latency().average().value());
/** * {@inheritDoc} */ @Override public long getSize() { if (cache.getCacheConfiguration().isTerracottaClustered()) { return getRemoteSizeSample().getMostRecentSample().getCounterValue(); } CacheTransactionHelper.beginTransactionIfNeeded(cache); try { return cache.getStatistics().getSize(); } catch (RuntimeException e) { throw Utils.newPlainException(e); } finally { try { CacheTransactionHelper.commitTransactionIfNeeded(cache); } catch (RuntimeException re) { throw Utils.newPlainException(re); } } }
final boolean overflowToOffHeap = cache.getCacheConfiguration().isOverflowToOffHeap(); maxElementsInMem = cache.getCacheConfiguration().getMaxEntriesLocalHeap() == 0 ? Integer.MAX_VALUE : cache.getCacheConfiguration().getMaxEntriesLocalHeap(); if (overflowToOffHeap) { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalOffHeap(); final long inMemoryCount = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSize() : cache.getStatistics().getLocalHeapSize(); if (inMemoryCount == 0L) { return false; } else { final long inMemorySizeInBytes = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSizeInBytes() : cache.getStatistics() .getLocalHeapSizeInBytes(); final long avgSize = inMemorySizeInBytes / inMemoryCount;
@Override public void clear() { pCacheHits = getEhcache().getStatistics().cacheHitCount(); pCacheMisses = getEhcache().getStatistics().cacheMissCount(); pCacheGets = getEhcache().getStatistics().cacheGetOperation().count().value(); pCachePuts = getEhcache().getStatistics().cachePutCount(); pCacheRemovals = getEhcache().getStatistics().cacheRemoveCount(); pCacheEvictions = getEhcache().getStatistics().cacheEvictedCount(); }
@Override public Double getValue() { return cache.getStatistics().cacheGetOperation().latency().average().value(); } });
@Override public Long getValue() { return cache.getStatistics().cacheHitCount(); } });
/** * Warning: This method can be very expensive to run. Allow approximately 1 second * per 1MB of entries. Running this method could create liveness problems * because the object lock is held for a long period * <p> * * @return the approximate size of memory ehcache is using for the MemoryStore for this cache */ public final long getSizeInMemory() { try { return cache.getStatistics().getLocalHeapSizeInBytes(); } catch (Throwable t) { return -1; } }
/** * {@inheritDoc} */ @Override public long getRemovedCount() { try { return cache.getStatistics().cacheRemoveCount(); } catch (RuntimeException e) { throw Utils.newPlainException(e); } }
/** * {@inheritDoc} */ @Override public long getEvictedCount() { try { return cache.getStatistics().cacheEvictedCount(); } catch (RuntimeException e) { throw Utils.newPlainException(e); } }
/** * {@inheritDoc} */ @Override public long getPutCount() { try { return cache.getStatistics().cachePutCount(); } catch (RuntimeException e) { throw Utils.newPlainException(e); } }