private Optional<Timer> requestDurationTimer(MetricId id) { return enabledMetrics.test(ENDPOINT_REQUEST_DURATION) ? Optional.of(metricRegistry .timer(id.tagged("what", ENDPOINT_REQUEST_DURATION.tag()))) : Optional.empty(); }
/** * A timer measures both the rate that a particular piece of code is called and the distribution * of its duration. For example we want to measure the rate and handling duration of incoming * requests. */ private static void reportTimer() { // Create or fetch (if it is already created) the metric. final Timer timer = registry.timer( APP_PREFIX.tagged("what", "incoming-request-time").tagged("endpoint", "/v1/get_stuff")); // Do this before starting to do the thing. This creates a measurement context object // that you can pass around. final Context context = timer.time(); // Do stuff that takes time (e.g., process the request) try { Thread.sleep(100); } catch (final InterruptedException e) { e.printStackTrace(); } // Tell the context that it's done. This will register the duration and counts one // occurrence. context.stop(); // 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 (all the // stats that you would get from a meter and a histogram are included) will be calculated // and // datapoints will be created and reported. }
public InstrumentedExecutorService( ExecutorService delegate, SemanticMetricRegistry registry, MetricId baseMetricId) { MetricId baseMetricIdWithUnit = baseMetricId.tagged("unit", "task"); this.delegate = delegate; 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.idle = registry.timer(baseMetricId.tagged("what", "idle")); this.duration = registry.timer(baseMetricId.tagged("what", "duration")); }
public InstrumentedExecutorService( ExecutorService delegate, SemanticMetricRegistry registry, MetricId baseMetricId) { MetricId baseMetricIdWithUnit = baseMetricId.tagged("unit", "task"); this.delegate = delegate; 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.idle = registry.timer(baseMetricId.tagged("what", "idle")); this.duration = registry.timer(baseMetricId.tagged("what", "duration")); }
static Metrics create(final SemanticMetricRegistry registry, final MetricId metricId) { final MetricId predictDurationId = metricId.tagged("what", PREDICT_DURATION.tag()); final MetricId predictRateId = metricId.tagged("what", PREDICT_RATE.tag()); final MetricId extractDuration = metricId.tagged("what", FEATURE_EXTRACT_DURATION.tag()); final MetricId extractRate = metricId.tagged("what", FEATURE_EXTRACT_RATE.tag()); final Timer predictTimer = registry.timer(predictDurationId); final Meter predictMeter = registry.meter(predictRateId); final Timer extractTimer = registry.timer(extractDuration); final Meter extractMeter = registry.meter(extractRate); return new AutoValue_SemanticPredictorMetrics_Metrics( predictTimer, predictMeter, extractTimer, extractMeter); } }
this.gets = registry.timer(getId); this.sets = registry.timer(setId); MetricId setMetersId = MetricId.join(setId, meterId); this.setSuccesses = registry.meter(setMetersId.tagged("result", "success")); this.multigets = registry.timer(multigetId); MetricId multigetMetersId = MetricId.join(multigetId, meterId); this.multigetSuccesses = registry.meter(multigetMetersId.tagged("result", "success")); this.deletes = registry.timer(deleteId); MetricId deleteMetersId = MetricId.join(deleteId, meterId); this.deleteSuccesses = registry.meter(deleteMetersId.tagged("result", "success")); this.incrDecrs = registry.timer(incrDecrId); MetricId incrDecrMetersId = MetricId.join(incrDecrId, meterId); this.incrDecrSuccesses = registry.meter(incrDecrMetersId.tagged("result", "success")); this.touches = registry.timer(touchId); MetricId touchMetersId = MetricId.join(touchId, meterId); this.touchSuccesses = registry.meter(touchMetersId.tagged("result", "success"));
/** * 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")); }