Java 类org.springframework.boot.actuate.cache.DefaultCacheStatistics 实例源码

项目:xlator    文件:RedisCacheMonitor.java   
@Scheduled(fixedDelay = 5000)
public void monitor() {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    // @see http://redis.io/commands/INFO
    RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
    try {
        Properties props = connection.info();
        Long hitCount = Long.parseLong(props.getProperty("keyspace_hits"));
        Long missCount = Long.parseLong(props.getProperty("keyspace_misses"));
        statistics.setGetCacheCounts(hitCount, missCount);
        // we do not currently have a way of calculating the cache size, so we have to filter
        List<Metric<?>> metrics = statistics
                                    .toMetrics("cache.")
                                        .stream()
                                            .filter(f -> !f.getName().contains(".size"))
                                            .collect(Collectors.toList());
        metrics.forEach(m -> metricServices.submit(m.getName(), (Double) m.getValue()));
    } finally {
        RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory);
    }
}
项目:JRediClients    文件:RedissonCacheStatisticsProvider.java   
@Override
public CacheStatistics getCacheStatistics(final CacheManager cacheManager, final RedissonCache cache) {
    final DefaultCacheStatistics defaultCacheStatistics = new DefaultCacheStatistics();
    defaultCacheStatistics.setSize((long) cache.getNativeCache().size());
    defaultCacheStatistics.setGetCacheCounts(cache.getCacheHits(), cache.getCacheMisses());
    return defaultCacheStatistics;
}
项目:xlator    文件:RedisCacheStatisticsProvider.java   
@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager, RedisCache cache) {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    // @see http://redis.io/commands/INFO
    RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
    try {
        Properties props = connection.info();
        Long hitCount = Long.parseLong(props.getProperty("keyspace_hits"));
        Long missCount = Long.parseLong(props.getProperty("keyspace_misses"));
        statistics.setGetCacheCounts(hitCount, missCount);
    } finally {
        RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory);
    }
    return statistics;
}