Search in sources :

Example 1 with SlidingTimeWindowReservoir

use of com.codahale.metrics.SlidingTimeWindowReservoir in project airpal by airbnb.

the class LocalUsageStore method markUsage.

@Override
public void markUsage(Table table) {
    Histogram window = usageMap.get(table);
    if (window == null) {
        final SlidingTimeWindowReservoir reservoir = new SlidingTimeWindowReservoir(usageTrackTime.getQuantity(), usageTrackTime.getUnit());
        window = new Histogram(reservoir);
        usageMap.put(table, window);
    }
    window.update(1);
}
Also used : SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) Histogram(com.codahale.metrics.Histogram)

Example 2 with SlidingTimeWindowReservoir

use of com.codahale.metrics.SlidingTimeWindowReservoir in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values.

@DataProvider(value = { "42     |   DAYS", "123    |   SECONDS", "999    |   MILLISECONDS", "3      |   HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
    // given
    RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
    // when
    Timer timer = rwtb.newMetric();
    // then
    Histogram histogram = (Histogram) getInternalState(timer, "histogram");
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 3 with SlidingTimeWindowReservoir

use of com.codahale.metrics.SlidingTimeWindowReservoir 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 4 with SlidingTimeWindowReservoir

use of com.codahale.metrics.SlidingTimeWindowReservoir in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values.

@DataProvider(value = { "42     |   DAYS", "123    |   SECONDS", "999    |   MILLISECONDS", "3      |   HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
    // given
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
    // when
    Histogram histogram = rwhb.newMetric();
    // then
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
Also used : Histogram(com.codahale.metrics.Histogram) RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 5 with SlidingTimeWindowReservoir

use of com.codahale.metrics.SlidingTimeWindowReservoir in project raml-module-builder by folio-org.

the class StatsTracker method addStatElement.

/**
 * add a metric (time) to a specific resource - for example
 * type = PostgresClient.get
 * time = single operation time in nanoseconds
 */
public static void addStatElement(String type, long time) {
    if (!registeredStatRequesters.contains(type)) {
        METRICS.register(type, new Histogram(new SlidingTimeWindowReservoir(60, TimeUnit.SECONDS)));
        registeredStatRequesters.add(type);
    }
    METRICS.histogram(type).update(time / 1000000);
}
Also used : SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) Histogram(com.codahale.metrics.Histogram)

Aggregations

SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)6 Histogram (com.codahale.metrics.Histogram)4 Reservoir (com.codahale.metrics.Reservoir)4 Test (org.junit.Test)3 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 UniformReservoir (com.codahale.metrics.UniformReservoir)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Clock (com.codahale.metrics.Clock)1 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 Timer (com.codahale.metrics.Timer)1 RollingWindowHistogramBuilder (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder)1 RollingWindowTimerBuilder (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder)1 NodeConfig (org.apache.solr.core.NodeConfig)1 PluginInfoInitialized (org.apache.solr.util.plugin.PluginInfoInitialized)1