private Optional<Histogram> responseSizeHistogram(MetricId id) { return enabledMetrics.test(RESPONSE_PAYLOAD_SIZE) ? Optional.of(metricRegistry.histogram( id.tagged( "what", RESPONSE_PAYLOAD_SIZE.tag(), "unit", "B" ))) : Optional.empty(); }
private Optional<Histogram> requestSizeHistogram(MetricId id) { return enabledMetrics.test(REQUEST_PAYLOAD_SIZE) ? Optional.of(metricRegistry.histogram( id.tagged( "what", REQUEST_PAYLOAD_SIZE.tag(), "unit", "B" ))) : Optional.empty(); }
private Optional<Histogram> fanoutHistogram(MetricId id) { return enabledMetrics.test(REQUEST_FANOUT_FACTOR) ? Optional.of(metricRegistry.histogram( id.tagged( "what", REQUEST_FANOUT_FACTOR.tag(), "unit", "request/request"))) : Optional.empty(); }
/** * A histogram measures the statistical distribution of values in a stream of data. In addition * to minimum, maximum, mean, etc., it also measures median, 75th, 90th, 95th, 98th, 99th, and * 99.9th percentiles. This histogram will measure the size of responses in bytes. */ private static void reportHistogram() { // Create or fetch (if it is already created) the metric. final Histogram histogram = registry.histogram( APP_PREFIX.tagged("what", "response-size").tagged("endpoint", "/v1/content")); // fetch the size of the response final long responseSize = 1000; // obviously this is gonna keep reporting 1000, but you know ;) histogram.update(responseSize); // That's it! The rest will be automatically done inside semantic metrics library. The // reported measurements will be kept in the registry. // Every time the reporter wants to report, different stats and aggregations (min, max, // median, 75th, 90th, 95th, 98th, 99th, and 99.9th percentiles) will be calculated and // datapoints will be created and reported. }
public static void main(String[] args) throws IOException { FastForwardReporter f = FastForwardReporter .forRegistry(registry) .histogramQuantiles(0.62, 0.55, 0.99) .schedule(TimeUnit.SECONDS, 10) .build(); f.start(); Histogram h = registry.histogram(APP_PREFIX.tagged("what", "stuff")); for (int i = 0; i < 100; i++) { h.update(i); } System.out.println("Sending custom percentiles for histogram..."); System.in.read(); f.stop(); } }
/** * Wraps an {@link java.util.concurrent.ScheduledExecutorService} with an explicit name. * * @param delegate {@link java.util.concurrent.ScheduledExecutorService} to wrap. * @param registry {@link SemanticMetricRegistry} that will contain the metrics. * @param baseMetricId base metric id for this executor service. */ public InstrumentedScheduledExecutorService( ScheduledExecutorService delegate, SemanticMetricRegistry registry, MetricId baseMetricId ) { this.delegate = delegate; MetricId baseMetricIdWithUnit = baseMetricId.tagged("unit", "task"); this.submitted = registry.meter(baseMetricIdWithUnit.tagged("what", "submitted")); this.running = registry.counter(baseMetricIdWithUnit.tagged("what", "running")); this.completed = registry.meter(baseMetricIdWithUnit.tagged("what", "completed")); this.duration = registry.timer(baseMetricIdWithUnit.tagged("what", "duration")); this.scheduledOnce = registry.meter(baseMetricIdWithUnit.tagged("what", "scheduled.once")); this.scheduledRepetitively = registry.meter(baseMetricIdWithUnit.tagged("what", "scheduled.repetitively")); this.scheduledOverrun = registry.counter(baseMetricIdWithUnit.tagged("what", "scheduled.overrun")); this.percentOfPeriod = registry.histogram(baseMetricIdWithUnit.tagged("what", "scheduled.percent-of-period")); }
/** * Wraps an {@link java.util.concurrent.ScheduledExecutorService} with an explicit name. * * @param delegate {@link java.util.concurrent.ScheduledExecutorService} to wrap. * @param registry {@link SemanticMetricRegistry} that will contain the metrics. * @param baseMetricId base metric id for this executor service. */ public InstrumentedScheduledExecutorService( ScheduledExecutorService delegate, SemanticMetricRegistry registry, MetricId baseMetricId ) { this.delegate = delegate; MetricId baseMetricIdWithUnit = baseMetricId.tagged("unit", "task"); this.submitted = registry.meter(baseMetricIdWithUnit.tagged("what", "submitted")); this.running = registry.counter(baseMetricIdWithUnit.tagged("what", "running")); this.completed = registry.meter(baseMetricIdWithUnit.tagged("what", "completed")); this.duration = registry.timer(baseMetricIdWithUnit.tagged("what", "duration")); this.scheduledOnce = registry.meter(baseMetricIdWithUnit.tagged("what", "scheduled.once")); this.scheduledRepetitively = registry.meter(baseMetricIdWithUnit.tagged("what", "scheduled.repetitively")); this.scheduledOverrun = registry.counter(baseMetricIdWithUnit.tagged("what", "scheduled.overrun")); this.percentOfPeriod = registry.histogram(baseMetricIdWithUnit.tagged("what", "scheduled.percent-of-period")); }