Search in sources :

Example 1 with ExponentiallyDecayingReservoir

use of com.codahale.metrics.ExponentiallyDecayingReservoir in project cassandra by apache.

the class DynamicEndpointSnitch method dumpTimings.

public List<Double> dumpTimings(String hostname) throws UnknownHostException {
    InetAddress host = InetAddress.getByName(hostname);
    ArrayList<Double> timings = new ArrayList<Double>();
    ExponentiallyDecayingReservoir sample = samples.get(host);
    if (sample != null) {
        for (double time : sample.getSnapshot().getValues()) timings.add(time);
    }
    return timings;
}
Also used : ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) InetAddress(java.net.InetAddress)

Example 2 with ExponentiallyDecayingReservoir

use of com.codahale.metrics.ExponentiallyDecayingReservoir in project cassandra by apache.

the class DynamicEndpointSnitch method receiveTiming.

public // this is cheap
void receiveTiming(// this is cheap
InetAddress host, // this is cheap
long latency) {
    ExponentiallyDecayingReservoir sample = samples.get(host);
    if (sample == null) {
        ExponentiallyDecayingReservoir maybeNewSample = new ExponentiallyDecayingReservoir(WINDOW_SIZE, ALPHA);
        sample = samples.putIfAbsent(host, maybeNewSample);
        if (sample == null)
            sample = maybeNewSample;
    }
    sample.update(latency);
}
Also used : ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir)

Example 3 with ExponentiallyDecayingReservoir

use of com.codahale.metrics.ExponentiallyDecayingReservoir in project jackrabbit-oak by apache.

the class CompositeStatsTest method timerContext.

@Test
public void timerContext() throws Exception {
    AtomicLong counter = new AtomicLong();
    VirtualClock clock = new VirtualClock();
    Timer time = new Timer(new ExponentiallyDecayingReservoir(), clock);
    TimerStats timerStats = new CompositeStats(counter, time);
    TimerStats.Context context = timerStats.time();
    clock.tick = TimeUnit.SECONDS.toNanos(314);
    context.close();
    assertEquals(1, time.getCount());
    assertEquals(TimeUnit.SECONDS.toMillis(314), counter.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) Timer(com.codahale.metrics.Timer) TimerStats(org.apache.jackrabbit.oak.stats.TimerStats) Test(org.junit.Test)

Example 4 with ExponentiallyDecayingReservoir

use of com.codahale.metrics.ExponentiallyDecayingReservoir in project lucene-solr by apache.

the class MetricSuppliers method getReservoir.

private static final Reservoir getReservoir(SolrResourceLoader loader, PluginInfo info) {
    if (info == null) {
        return new ExponentiallyDecayingReservoir();
    }
    Clock clk = getClock(info, CLOCK);
    String clazz = ExponentiallyDecayingReservoir.class.getName();
    int size = -1;
    double alpha = -1;
    long window = -1;
    if (info.initArgs != null) {
        if (info.initArgs.get(RESERVOIR) != null) {
            String val = String.valueOf(info.initArgs.get(RESERVOIR)).trim();
            if (!val.isEmpty()) {
                clazz = val;
            }
        }
        Number n = (Number) info.initArgs.get(RESERVOIR_SIZE);
        if (n != null) {
            size = n.intValue();
        }
        n = (Number) info.initArgs.get(RESERVOIR_EDR_ALPHA);
        if (n != null) {
            alpha = n.doubleValue();
        }
        n = (Number) info.initArgs.get(RESERVOIR_WINDOW);
        if (n != null) {
            window = n.longValue();
        }
    }
    if (size <= 0) {
        size = DEFAULT_SIZE;
    }
    if (alpha <= 0) {
        alpha = DEFAULT_ALPHA;
    }
    // special case for core implementations
    if (clazz.equals(EDR_CLAZZ)) {
        return new ExponentiallyDecayingReservoir(size, alpha, clk);
    } else if (clazz.equals(UNI_CLAZZ)) {
        return new UniformReservoir(size);
    } else if (clazz.equals(STW_CLAZZ)) {
        if (window <= 0) {
            // 5 minutes, comparable to EDR
            window = DEFAULT_WINDOW;
        }
        return new SlidingTimeWindowReservoir(window, TimeUnit.SECONDS);
    } else if (clazz.equals(SW_CLAZZ)) {
        return new SlidingWindowReservoir(size);
    } else {
        // custom reservoir
        Reservoir reservoir;
        try {
            reservoir = loader.newInstance(clazz, Reservoir.class);
            if (reservoir instanceof PluginInfoInitialized) {
                ((PluginInfoInitialized) reservoir).init(info);
            } else {
                SolrPluginUtils.invokeSetters(reservoir, info.initArgs, true);
            }
            return reservoir;
        } catch (Exception e) {
            log.warn("Error initializing custom Reservoir implementation (will use default): " + info, e);
            return new ExponentiallyDecayingReservoir(size, alpha, clk);
        }
    }
}
Also used : Reservoir(com.codahale.metrics.Reservoir) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) UniformReservoir(com.codahale.metrics.UniformReservoir) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) Clock(com.codahale.metrics.Clock) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) UniformReservoir(com.codahale.metrics.UniformReservoir) PluginInfoInitialized(org.apache.solr.util.plugin.PluginInfoInitialized)

Example 5 with ExponentiallyDecayingReservoir

use of com.codahale.metrics.ExponentiallyDecayingReservoir in project sling by apache.

the class MetricWrapperTest method timerContext.

@Test
public void timerContext() throws Exception {
    VirtualClock clock = new VirtualClock();
    Timer time = new Timer(new ExponentiallyDecayingReservoir(), clock);
    TimerImpl timerStats = new TimerImpl(time);
    org.apache.sling.commons.metrics.Timer.Context context = timerStats.time();
    clock.tick = TimeUnit.SECONDS.toNanos(314);
    context.close();
    assertEquals(1, time.getCount());
    assertEquals(TimeUnit.SECONDS.toNanos(314), time.getSnapshot().getMax());
}
Also used : ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) Timer(com.codahale.metrics.Timer) Test(org.junit.Test)

Aggregations

ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)7 Test (org.junit.Test)4 Timer (com.codahale.metrics.Timer)3 Clock (com.codahale.metrics.Clock)2 Reservoir (com.codahale.metrics.Reservoir)2 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)2 UniformReservoir (com.codahale.metrics.UniformReservoir)2 TimerStats (org.apache.jackrabbit.oak.stats.TimerStats)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 InetAddress (java.net.InetAddress)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 NodeConfig (org.apache.solr.core.NodeConfig)1 PluginInfoInitialized (org.apache.solr.util.plugin.PluginInfoInitialized)1