Search in sources :

Example 31 with Histogram

use of com.codahale.metrics.Histogram in project dropwizard by dropwizard.

the class BootstrapTest method bringsYourOwnMetricRegistry.

@Test
public void bringsYourOwnMetricRegistry() {
    final MetricRegistry newRegistry = new MetricRegistry() {

        @Override
        public Histogram histogram(String name) {
            Histogram existed = (Histogram) getMetrics().get(name);
            return existed != null ? existed : new Histogram(new UniformReservoir());
        }
    };
    bootstrap.setMetricRegistry(newRegistry);
    bootstrap.registerMetrics();
    assertThat(newRegistry.getNames()).contains("jvm.buffers.mapped.capacity", "jvm.threads.count", "jvm.memory.heap.usage", "jvm.attribute.vendor", "jvm.classloader.loaded", "jvm.filedescriptor");
}
Also used : Histogram(com.codahale.metrics.Histogram) MetricRegistry(com.codahale.metrics.MetricRegistry) UniformReservoir(com.codahale.metrics.UniformReservoir) Test(org.junit.Test)

Example 32 with Histogram

use of com.codahale.metrics.Histogram in project jstorm by alibaba.

the class TopologyMetricContext method mergeHistograms.

/**
     * histograms are sampled, but we just update points
     */
public void mergeHistograms(MetricInfo metricInfo, String meta, Map<Integer, MetricSnapshot> data, Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) {
    Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
    if (existing == null) {
        metricInfo.put_to_metrics(meta, data);
        Map<Integer, Histogram> histogramMap = new HashMap<>();
        for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
            Histogram histogram = MetricUtils.metricSnapshot2Histogram(dataEntry.getValue());
            histogramMap.put(dataEntry.getKey(), histogram);
        }
        histograms.put(meta, histogramMap);
    } else {
        for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
            Integer win = dataEntry.getKey();
            MetricSnapshot snapshot = dataEntry.getValue();
            MetricSnapshot old = existing.get(win);
            if (old == null) {
                existing.put(win, snapshot);
                histograms.get(meta).put(win, MetricUtils.metricSnapshot2Histogram(snapshot));
            } else {
                if (snapshot.get_ts() >= old.get_ts()) {
                    old.set_ts(snapshot.get_ts());
                    Histogram histogram = histograms.get(meta).get(win);
                    Snapshot updateSnapshot = histogram.getSnapshot();
                    if (updateSnapshot instanceof JAverageSnapshot) {
                        averageMetricSnapshot(((JAverageSnapshot) updateSnapshot).getMetricSnapshot(), snapshot);
                    } else {
                        // update points
                        MetricUtils.updateHistogramPoints(histogram, snapshot.get_points(), snapshot.get_pointSize());
                    }
                }
            }
        }
    }
    updateMetricCounters(meta, metaCounters);
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot) Snapshot(com.codahale.metrics.Snapshot) JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) Histogram(com.codahale.metrics.Histogram) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) MetricSnapshot(backtype.storm.generated.MetricSnapshot) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 33 with Histogram

use of com.codahale.metrics.Histogram in project torodb by torodb.

the class ConcurrentOplogBatchExecutorTest method testExecute.

@Test
public void testExecute() throws Exception {
    int batchSize = 100;
    int opsPerJob = 20;
    int subBatchSize = 11;
    int subBatchesPerJob = opsPerJob / subBatchSize + (opsPerJob % subBatchSize != 0 ? 1 : 0);
    int expectedSize = batchSize * subBatchesPerJob;
    //GIVEN
    CudAnalyzedOplogBatch batch = mock(CudAnalyzedOplogBatch.class);
    List<NamespaceJob> jobs = new ArrayList<>();
    for (int i = 0; i < batchSize; i++) {
        jobs.add(new NamespaceJob("db", "col", Lists.newArrayList(Stream.iterate(createAnalyzedOp(null), this::createAnalyzedOp).limit(opsPerJob).iterator())));
    }
    AtomicInteger callablesCounter = new AtomicInteger(0);
    ApplierContext context = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
    Histogram mockHistogram = mock(Histogram.class);
    Meter mockMeter = mock(Meter.class);
    given(batch.streamNamespaceJobs()).willReturn(jobs.stream());
    given(subBatchHeuristic.getSubBatchSize(any())).willReturn(subBatchSize);
    given(metrics.getSubBatchSizeHistogram()).willReturn(mockHistogram);
    given(metrics.getSubBatchSizeMeter()).willReturn(mockMeter);
    given(streamExecutor.execute(any())).willAnswer(new Answer<CompletableFuture<?>>() {

        @Override
        public CompletableFuture<?> answer(InvocationOnMock invocation) throws Throwable {
            CompletableFuture<Object> completableFuture = new CompletableFuture<>();
            completableFuture.complete(new Object());
            Stream<Callable<?>> callables = invocation.getArgument(0);
            callablesCounter.addAndGet((int) callables.count());
            return completableFuture;
        }
    });
    //WHEN
    executor.execute(batch, context);
    //THEN
    then(mockHistogram).should().update(expectedSize);
    then(mockMeter).should().mark(expectedSize);
    assertEquals(expectedSize, callablesCounter.get());
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) ArrayList(java.util.ArrayList) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Stream(java.util.stream.Stream) Test(org.junit.Test)

Example 34 with Histogram

use of com.codahale.metrics.Histogram in project graylog2-server by Graylog2.

the class SearchesTest method fieldStatsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void fieldStatsRecordsMetrics() throws Exception {
    FieldStatsResult result = searches.fieldStats("n", "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 35 with Histogram

use of com.codahale.metrics.Histogram in project graylog2-server by Graylog2.

the class SearchesTest method termsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void termsRecordsMetrics() throws Exception {
    TermsResult result = searches.terms("n", 25, "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) TermsResult(org.graylog2.indexer.results.TermsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)44 Test (org.junit.Test)21 Timer (com.codahale.metrics.Timer)17 Meter (com.codahale.metrics.Meter)13 Counter (com.codahale.metrics.Counter)12 Snapshot (com.codahale.metrics.Snapshot)11 MetricRegistry (com.codahale.metrics.MetricRegistry)8 Gauge (com.codahale.metrics.Gauge)7 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 ZonedDateTime (java.time.ZonedDateTime)5 Map (java.util.Map)5 DateTime (org.joda.time.DateTime)5 Metric (com.codahale.metrics.Metric)4 UniformReservoir (com.codahale.metrics.UniformReservoir)3 SortedMap (java.util.SortedMap)3 AggregateMetric (org.apache.solr.metrics.AggregateMetric)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 MetricFilter (com.codahale.metrics.MetricFilter)2