Example usage for com.google.common.cache CacheStats requestCount

List of usage examples for com.google.common.cache CacheStats requestCount

Introduction

In this page you can find the example usage for com.google.common.cache CacheStats requestCount.

Prototype

public long requestCount() 

Source Link

Document

Returns the number of times Cache lookup methods have returned either a cached or uncached value.

Usage

From source file:org.springframework.boot.actuate.cache.GuavaCacheStatisticsProvider.java

@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager, GuavaCache cache) {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    statistics.setSize(cache.getNativeCache().size());
    CacheStats guavaStats = cache.getNativeCache().stats();
    if (guavaStats.requestCount() > 0) {
        statistics.setHitRatio(guavaStats.hitRate());
        statistics.setMissRatio(guavaStats.missRate());
    }/*w ww  .jav a  2s  .  com*/
    return statistics;
}

From source file:com.ebay.pulsar.analytics.datasource.DataSourceMetaRepo.java

public Map<String, Object> getStats() {
    // Get Cache Stats: requestCount, hitRate
    Map<String, Object> map = Maps.newHashMap();
    CacheStats stats = cache.stats();

    Long reqCount = stats.requestCount();
    Double hitRate = stats.hitRate();
    map.put("requestCount", reqCount);
    map.put("hitRate", hitRate);
    return map;/*from  www . j a  v  a 2s  .c o m*/
}

From source file:com.adobe.acs.commons.util.impl.AbstractGuavaCacheMBean.java

@Override
@SuppressWarnings("squid:S1192")
public final TabularData getCacheStats() throws OpenDataException {
    // Exposing all google guava stats.
    final CompositeType cacheEntryType = new CompositeType(JMX_PN_CACHESTATS, JMX_PN_CACHESTATS,
            new String[] { JMX_PN_STAT, JMX_PN_VALUE }, new String[] { JMX_PN_STAT, JMX_PN_VALUE },
            new OpenType[] { SimpleType.STRING, SimpleType.STRING });

    final TabularDataSupport tabularData = new TabularDataSupport(new TabularType(JMX_PN_CACHESTATS,
            JMX_PN_CACHESTATS, cacheEntryType, new String[] { JMX_PN_STAT }));

    CacheStats cacheStats = getCache().stats();

    final Map<String, Object> row = new HashMap<String, Object>();

    row.put(JMX_PN_STAT, "Request Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.requestCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Hit Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.hitCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Hit Rate");
    row.put(JMX_PN_VALUE, String.format("%.0f%%", cacheStats.hitRate() * 100));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Miss Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.missCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Miss Rate");
    row.put(JMX_PN_VALUE, String.format("%.0f%%", cacheStats.missRate() * 100));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Eviction Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.evictionCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Load Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.loadCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Load Exception Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.loadExceptionCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Load Exception Rate");
    row.put(JMX_PN_VALUE, String.format("%.0f%%", cacheStats.loadExceptionRate() * 100));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Load Success Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.loadSuccessCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Average Load Penalty");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.averageLoadPenalty()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    row.put(JMX_PN_STAT, "Total Load Time");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.totalLoadTime()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));

    return tabularData;
}

From source file:com.facebook.buck.rules.keys.EventPostingRuleKeyCacheScope.java

@Override
public final void close() {
    try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus,
            PerfEventId.of("rule_key_cache_cleanup"))) {

        // Log stats.
        CacheStats stats = cache.getStats().minus(startStats);
        buckEventBus.post(RuleKeyCacheStatsEvent.create(stats));
        scope.update("hitRate", stats.hitRate());
        scope.update("hits", stats.hitCount());
        scope.update("misses", stats.missCount());
        scope.update("requests", stats.requestCount());
        scope.update("load_time_ns", stats.totalLoadTime());

        // Run additional cleanup.
        cleanup(scope);/*  ww w .  ja  v  a2s  .  c o  m*/
    }
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.util.DataExporter.java

private Map<String, Object> createCacheStatsMap(final CacheStats cacheStats) {
    final Map<String, Object> cacheStatsMap = new HashMap<String, Object>();
    cacheStatsMap.put("requestCount", cacheStats.requestCount());
    cacheStatsMap.put("hitCount", cacheStats.hitCount());
    cacheStatsMap.put("missCount", cacheStats.missCount());
    cacheStatsMap.put("hitRate", cacheStats.hitRate());
    cacheStatsMap.put("missRate", cacheStats.missRate());
    cacheStatsMap.put("evictionCount", cacheStats.evictionCount());
    cacheStatsMap.put("loadCount", cacheStats.loadCount());
    cacheStatsMap.put("loadSuccessCount", cacheStats.loadSuccessCount());
    cacheStatsMap.put("loadExceptionCount", cacheStats.loadExceptionCount());
    cacheStatsMap.put("loadExceptionRate", cacheStats.loadExceptionRate());
    cacheStatsMap.put("totalLoadTime", cacheStats.totalLoadTime());
    cacheStatsMap.put("averageLoadPenalty", cacheStats.averageLoadPenalty());
    return cacheStatsMap;
}

From source file:com.google.gerrit.sshd.commands.ShowCaches.java

private void printMemoryCaches(Map<String, H2CacheImpl<?, ?>> disks, Map<String, Cache<?, ?>> caches) {
    for (Map.Entry<String, Cache<?, ?>> entry : caches.entrySet()) {
        Cache<?, ?> cache = entry.getValue();
        if (cache instanceof H2CacheImpl) {
            disks.put(entry.getKey(), (H2CacheImpl<?, ?>) cache);
            continue;
        }/*from ww w  .ja  v a 2  s. co  m*/
        CacheStats stat = cache.stats();
        stdout.print(String.format("  %-" + nw + "s|%6s %6s %7s| %7s |%4s %4s|\n", entry.getKey(),
                count(cache.size()), "", "", duration(stat.averageLoadPenalty()),
                percent(stat.hitCount(), stat.requestCount()), ""));
    }
}

From source file:com.google.gerrit.sshd.commands.ShowCaches.java

@Override
protected void run() {
    nw = columns - 50;//from  w w  w.  j a  va2 s  . c o m
    Date now = new Date();
    stdout.format("%-25s %-20s      now  %16s\n", "Gerrit Code Review",
            Version.getVersion() != null ? Version.getVersion() : "",
            new SimpleDateFormat("HH:mm:ss   zzz").format(now));
    stdout.format("%-25s %-20s   uptime %16s\n", "", "", uptime(now.getTime() - serverStarted));
    stdout.print('\n');

    stdout.print(String.format(//
            "%1s %-" + nw + "s|%-21s|  %-5s |%-9s|\n" //
            , "" //
            , "Name" //
            , "Entries" //
            , "AvgGet" //
            , "Hit Ratio" //
    ));
    stdout.print(String.format(//
            "%1s %-" + nw + "s|%6s %6s %7s|  %-5s  |%-4s %-4s|\n" //
            , "" //
            , "" //
            , "Mem" //
            , "Disk" //
            , "Space" //
            , "" //
            , "Mem" //
            , "Disk" //
    ));
    stdout.print("--");
    for (int i = 0; i < nw; i++) {
        stdout.print('-');
    }
    stdout.print("+---------------------+---------+---------+\n");

    Map<String, H2CacheImpl<?, ?>> disks = Maps.newTreeMap();
    printMemoryCaches(disks, sortedCoreCaches());
    printMemoryCaches(disks, sortedPluginCaches());
    for (Map.Entry<String, H2CacheImpl<?, ?>> entry : disks.entrySet()) {
        H2CacheImpl<?, ?> cache = entry.getValue();
        CacheStats stat = cache.stats();
        H2CacheImpl.DiskStats disk = cache.diskStats();
        stdout.print(String.format("D %-" + nw + "s|%6s %6s %7s| %7s |%4s %4s|\n", entry.getKey(),
                count(cache.size()), count(disk.size()), bytes(disk.space()),
                duration(stat.averageLoadPenalty()), percent(stat.hitCount(), stat.requestCount()),
                percent(disk.hitCount(), disk.requestCount())));
    }
    stdout.print('\n');

    if (gc) {
        System.gc();
        System.runFinalization();
        System.gc();
    }

    sshSummary();
    taskSummary();
    memSummary();

    if (showJVM) {
        jvmSummary();
    }

    stdout.flush();
}