use of com.codahale.metrics.Histogram in project apollo by spotify.
the class RouteTransformMetricsExampleTest method responsePayloadSizeHistogram.
/**
* Middleware to track response payload size in a Histogram,
* tagged with an endpoint tag set to the given endpoint name.
*/
public Middleware<AsyncHandler<Response<ByteString>>, AsyncHandler<Response<ByteString>>> responsePayloadSizeHistogram(String endpointName) {
final MetricId histogramId = MetricId.build().tagged("service", serviceName).tagged("endpoint", endpointName).tagged("what", "endpoint-response-size");
final Histogram histogram = registry.histogram(histogramId);
return (inner) -> (requestContext) -> inner.invoke(requestContext).whenComplete((response, t) -> {
if (response != null) {
histogram.update(response.payload().map(ByteString::size).orElse(0));
}
});
}
use of com.codahale.metrics.Histogram in project atlasdb by palantir.
the class MetricsManager method registerOrGetHistogram.
private Histogram registerOrGetHistogram(String fullyQualifiedHistogramName) {
Histogram histogram = metricRegistry.histogram(fullyQualifiedHistogramName);
registeredMetrics.add(fullyQualifiedHistogramName);
return histogram;
}
use of com.codahale.metrics.Histogram in project incubator-gobblin by apache.
the class OutputStreamReporterTest method testReporter.
@Test
public void testReporter() throws IOException {
MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName()).build();
Counter counter = metricContext.counter("com.linkedin.example.counter");
Meter meter = metricContext.meter("com.linkedin.example.meter");
Histogram histogram = metricContext.histogram("com.linkedin.example.histogram");
OutputStreamReporter reporter = OutputStreamReporter.Factory.newBuilder().outputTo(this.stream).build(new Properties());
counter.inc();
meter.mark(2);
histogram.update(1);
histogram.update(1);
histogram.update(2);
reporter.report();
String[] lines = this.stream.toString().split("\n");
Map<String, Set<String>> expected = new HashMap<>();
Set<String> counterSubMetrics = new HashSet<>();
counterSubMetrics.add("count");
expected.put("com.linkedin.example.counter", counterSubMetrics);
Set<String> histogramSubMetrics = new HashSet<>();
histogramSubMetrics.add("count");
histogramSubMetrics.add("min");
histogramSubMetrics.add("max");
histogramSubMetrics.add("mean");
histogramSubMetrics.add("stddev");
histogramSubMetrics.add("median");
histogramSubMetrics.add("75% <");
histogramSubMetrics.add("95% <");
expected.put("com.linkedin.example.histogram", histogramSubMetrics);
Set<String> meterSubmetrics = new HashSet<>();
meterSubmetrics.add("count");
meterSubmetrics.add("mean rate");
meterSubmetrics.add("1-minute rate");
meterSubmetrics.add("5-minute rate");
meterSubmetrics.add("15-minute rate");
expected.put("com.linkedin.example.meter", meterSubmetrics);
expectMetrics(expected, lines);
reporter.close();
}
use of com.codahale.metrics.Histogram in project incubator-gobblin by apache.
the class InfluxDBReporterTest method testWithTags.
@Test
public void testWithTags() throws IOException {
try (MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName() + ".testGraphiteReporter").addTag(new Tag<String>("taskId", "task_testjob_123")).addTag(new Tag<String>("forkBranchName", "fork_1")).build();
InfluxDBReporter influxDBReporter = InfluxDBReporter.Factory.newBuilder().withInfluxDBPusher(influxDBPusher).withMetricContextName(CONTEXT_NAME).build(new Properties())) {
Counter counter = metricContext.counter(MetricRegistry.name(METRIC_PREFIX, COUNTER));
counter.inc(5l);
influxDBReporter.report(new TreeMap<String, Gauge>(), metricContext.getCounters(), new TreeMap<String, Histogram>(), new TreeMap<String, Meter>(), new TreeMap<String, Timer>(), metricContext.getTagMap());
// InfluxDB converts all values to float64 internally
Assert.assertEquals(getMetricValue("task_testjob_123.fork_1." + METRIC_PREFIX, COUNTER, Measurements.COUNT), Float.toString(5f));
}
}
use of com.codahale.metrics.Histogram in project incubator-gobblin by apache.
the class HadoopCounterReporterTest method testReportMetrics.
@Test
public void testReportMetrics() {
Gauge<Integer> queueSizeGauge = new Gauge<Integer>() {
@Override
public Integer getValue() {
return 1000;
}
};
Counter recordsProcessedCounter = new Counter();
recordsProcessedCounter.inc(10l);
Histogram recordSizeDistributionHistogram = new Histogram(new ExponentiallyDecayingReservoir());
recordSizeDistributionHistogram.update(1);
recordSizeDistributionHistogram.update(2);
recordSizeDistributionHistogram.update(3);
Meter recordProcessRateMeter = new Meter();
recordProcessRateMeter.mark(1l);
recordProcessRateMeter.mark(2l);
recordProcessRateMeter.mark(3l);
Timer totalDurationTimer = new Timer();
totalDurationTimer.update(1, TimeUnit.SECONDS);
totalDurationTimer.update(2, TimeUnit.SECONDS);
totalDurationTimer.update(3, TimeUnit.SECONDS);
SortedMap<String, Counter> counters = ImmutableSortedMap.<String, Counter>naturalOrder().put(RECORDS_PROCESSED, recordsProcessedCounter).build();
SortedMap<String, Gauge> gauges = ImmutableSortedMap.<String, Gauge>naturalOrder().put(QUEUE_SIZE, queueSizeGauge).build();
SortedMap<String, Histogram> histograms = ImmutableSortedMap.<String, Histogram>naturalOrder().put(RECORD_SIZE_DISTRIBUTION, recordSizeDistributionHistogram).build();
SortedMap<String, Meter> meters = ImmutableSortedMap.<String, Meter>naturalOrder().put(RECORD_PROCESS_RATE, recordProcessRateMeter).build();
SortedMap<String, Timer> timers = ImmutableSortedMap.<String, Timer>naturalOrder().put(TOTAL_DURATION, totalDurationTimer).build();
this.hadoopCounterReporter.report(gauges, counters, histograms, meters, timers);
Mockito.verify(this.recordsProcessedCount).increment(10l);
Mockito.verify(this.recordProcessRateCount).increment(6l);
Mockito.verify(this.recordSizeDistributionCount).increment(3l);
Mockito.verify(this.totalDurationCount).increment(3l);
Mockito.verify(this.queueSize).setValue(1000);
recordsProcessedCounter.inc(5l);
recordSizeDistributionHistogram.update(4);
recordProcessRateMeter.mark(4l);
totalDurationTimer.update(4, TimeUnit.SECONDS);
this.hadoopCounterReporter.report(gauges, counters, histograms, meters, timers);
Mockito.verify(this.recordsProcessedCount).increment(5l);
Mockito.verify(this.recordProcessRateCount).increment(4l);
Mockito.verify(this.recordSizeDistributionCount).increment(1l);
Mockito.verify(this.totalDurationCount).increment(1l);
}
Aggregations