Search in sources :

Example 71 with Histogram

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));
        }
    });
}
Also used : Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Histogram(com.codahale.metrics.Histogram) Response(com.spotify.apollo.Response) AsyncHandler(com.spotify.apollo.route.AsyncHandler) RequestContext(com.spotify.apollo.RequestContext) Matchers.allOf(org.hamcrest.Matchers.allOf) MetricId(com.spotify.metrics.core.MetricId) SemanticMetricRegistry(com.spotify.metrics.core.SemanticMetricRegistry) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Middleware(com.spotify.apollo.route.Middleware) Route(com.spotify.apollo.route.Route) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ByteString(okio.ByteString) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MetricId(com.spotify.metrics.core.MetricId) Histogram(com.codahale.metrics.Histogram) ByteString(okio.ByteString)

Example 72 with Histogram

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;
}
Also used : Histogram(com.codahale.metrics.Histogram)

Example 73 with 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();
}
Also used : Histogram(com.codahale.metrics.Histogram) Set(java.util.Set) HashSet(java.util.HashSet) Meter(com.codahale.metrics.Meter) HashMap(java.util.HashMap) Properties(java.util.Properties) OutputStreamReporter(org.apache.gobblin.metrics.reporter.OutputStreamReporter) Counter(com.codahale.metrics.Counter) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 74 with Histogram

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));
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Properties(java.util.Properties) ContextAwareGauge(org.apache.gobblin.metrics.ContextAwareGauge) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) MetricContext(org.apache.gobblin.metrics.MetricContext) Tag(org.apache.gobblin.metrics.Tag) Test(org.testng.annotations.Test)

Example 75 with Histogram

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);
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Gauge(com.codahale.metrics.Gauge) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Test(org.testng.annotations.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)97 Test (org.junit.Test)39 Timer (com.codahale.metrics.Timer)34 Counter (com.codahale.metrics.Counter)30 Meter (com.codahale.metrics.Meter)29 Gauge (com.codahale.metrics.Gauge)17 Snapshot (com.codahale.metrics.Snapshot)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Metric (com.codahale.metrics.Metric)6 Reservoir (com.codahale.metrics.Reservoir)6 ZonedDateTime (java.time.ZonedDateTime)6 Properties (java.util.Properties)6 SortedMap (java.util.SortedMap)6 DateTime (org.joda.time.DateTime)6 UniformReservoir (com.codahale.metrics.UniformReservoir)5