Java 类com.codahale.metrics.CachedGauge 实例源码

项目:HeliosStreams    文件:PluginMetricManager.java   
/**
 * Acquires the named cached gauge 
 * @param name The name of the gauge
 * @param provider The value provider for the gauge
 * @param refreshPeriod The refresh period of the cached gauge in seconds
 * @return the cached gauge
 */
public <T> CachedGauge<T> gauge(final String name, final Callable<T> provider, final int refreshPeriod) {
    final String fullName = name + serviceTag;
    final CachedGauge<T> g = new CachedGauge<T>(refreshPeriod, TimeUnit.SECONDS) {
        @Override
        protected T loadValue() {
            try {
            return provider.call();
            } catch (Exception ex) {
                throw new RuntimeException("Failed to get cached value for [" + name + "]", ex);
            }
        }
    };
    metricRegistry.register("gauge." + fullName, g);
    gauges.put(name, g);
    return g;
}
项目:HeliosStreams    文件:PluginMetricManager.java   
/**
 * Acquires the named cached gauge 
 * @param name The name of the gauge
 * @param provider The value provider for the gauge
 * @param refreshPeriod The refresh period of the cached gauge in seconds
 * @return the cached gauge
 */
public <T> CachedGauge<T> gauge(final String name, final Callable<T> provider, final int refreshPeriod) {
    final String fullName = name + serviceTag;
    final CachedGauge<T> g = new CachedGauge<T>(refreshPeriod, TimeUnit.SECONDS) {
        @Override
        protected T loadValue() {
            try {
            return provider.call();
            } catch (Exception ex) {
                throw new RuntimeException("Failed to get cached value for [" + name + "]", ex);
            }
        }
    };
    metricRegistry.register("gauge." + fullName, g);
    gauges.put(name, g);
    return g;
}
项目:spike.x    文件:Activator.java   
private void registerAggregateMetrics(final MetricRegistry registry) {
    //
    // JVM used percentage
    //
    Map<String, Gauge> gauges = registry.getGauges();
    final Gauge<Long> gaugeJvmMemMax = gauges.get("jvm.memory.total.max");
    final Gauge<Long> gaugeJvmMemUsed = gauges.get("jvm.memory.total.used");

    registry.register(JVM_MEM_PERC.key(), new CachedGauge<Double>(5L, TimeUnit.SECONDS) {

        @Override
        protected Double loadValue() {
            double memMax = gaugeJvmMemMax.getValue();
            double memUsed = gaugeJvmMemUsed.getValue();
            return (memUsed / memMax) * 100.0d;
        }
    });
}
项目:HeliosStreams    文件:NodeConfigurationServer.java   
/**
 * {@inheritDoc}
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 */
@Override
public void afterPropertiesSet() throws Exception {     
    configDir = new File(configDirName).getAbsoluteFile();
    appDir = new File(appDirName).getAbsoluteFile();
    if(!configDir.isDirectory()) throw new IllegalArgumentException("The configuration directory [" + configDirName + "] is invalid");
    if(!appDir.exists()) {
        appDir.mkdirs();
    }
    if(!appDir.isDirectory()) throw new IllegalArgumentException("The app directory [" + appDirName + "] is invalid");
    log.info("Configuration Directory: [{}]", configDir);
    if(!cacheSpec.contains("recordStats")) cacheSpec = cacheSpec + ",recordStats";

    configCache = CacheBuilder.from(cacheSpec).build(configCacheLoader);
    configCacheStats = new CachedGauge<CacheStats>(5, TimeUnit.SECONDS) {
        @Override
        protected CacheStats loadValue() {              
            return configCache.stats();
        }
    };
    appJarCache = CacheBuilder.from(cacheSpec).build(appJarCacheLoader);
    appJarCacheStats = new CachedGauge<CacheStats>(5, TimeUnit.SECONDS) {
        @Override
        protected CacheStats loadValue() {              
            return appJarCache.stats();
        }
    };

    reloadConfigCache();
    log.info("Loaded [{}] App Configurations", configCache.size());
    reloadAppJarCache();
    log.info("Loaded [{}] App Jar Sets", appJarCache.size());
}
项目:HeliosStreams    文件:TSDBEndpoint.java   
/**
 * Creates a new TSDBEndpoint
 * @param sqlWorker The SQLWorker that will drive the lookups
 */
private TSDBEndpoint(final SQLWorker sqlWorker) {
    this.sqlWorker = sqlWorker;
    knownServers = new CachedGauge<String[]>(60, TimeUnit.SECONDS) {
        @Override
        protected String[] loadValue() {
            final String order = (asc.getAndSet(asc.get()) ? "ASC" : "DESC"); 
            return sqlWorker.sqlForFormat(null, null, "SELECT HOST, PORT, URI FROM TSD_KNOWNSERVERS WHERE UP = 'Y' ORDER BY HOST " + order + ", PORT " + order, "http://##0##:##1##/##2##");
        }
    };
}
项目:carbon-metrics    文件:CachedGaugeImpl.java   
public CachedGaugeImpl(String name, Level level, long timeout, TimeUnit timeoutUnit, final Gauge<T> gauge) {
    super(name, level);
    this.gauge = new CachedGauge<T>(timeout, timeoutUnit) {
        @Override
        protected T loadValue() {
            return gauge.getValue();
        }
    };
}
项目:oap    文件:Metrics.java   
public static <T> void measureCachedGauge( String metric, long timeout, TimeUnit timeUnit, Supplier<T> get ) {
    registry.register( metric, new CachedGauge<T>( timeout, timeUnit ) {
        @Override
        protected T loadValue() {
            return get.get();
        }
    } );
}
项目:oap    文件:Metrics.java   
public static <T> Name measureCachedGauge( Name metric, long timeout, TimeUnit timeUnit, Supplier<T> get ) {
    registry.register( metric.line, new CachedGauge<T>( timeout, timeUnit ) {
        @Override
        protected T loadValue() {
            return get.get();
        }
    } );
    return metric;
}