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");
}
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);
}
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());
}
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);
}
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);
}
Aggregations