private void stop(Timer.Sample timerSample, Supplier<Iterable<Tag>> tags, Builder builder) { timerSample.stop(builder.tags(tags.get()).register(this.registry)); }
shortSample.stop(timer);
@Override @Nullable public T poll() { if (qs == null) { return null; } try { T v = qs.poll(); if (v == null && fusionMode == SYNC) { //this is also a complete event this.subscribeToTerminateSample.stop(subscribeToCompleteTimer); } if (v != null) { //this is an onNext event //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); } return v; } catch (Throwable e) { //register a timer for that particular exception Timer timer = subscribeToErrorTimerFactory.apply(e); //record error termination this.subscribeToTerminateSample.stop(timer); throw e; } }
@Override @Nullable public T poll() { if (qs == null) { return null; } try { T v = qs.poll(); if (v == null && this.mode == SYNC) { //this is also a complete event this.subscribeToTerminateSample.stop(subscribeToCompleteTimer); } return v; } catch (Throwable e) { //register a timer for that particular exception Timer timer = subscribeToErrorTimerFactory.apply(e); //record error termination this.subscribeToTerminateSample.stop(timer); throw e; } }
private Object timedProceed(ProceedingJoinPoint pjp, Timed timed) throws Throwable { if (timed.value().isEmpty()) { return pjp.proceed(); } Timer.Sample sample = Timer.start(registry); try { return pjp.proceed(); } finally { sample.stop( Timer.builder(timed.value()) .description(timed.description().isEmpty() ? null : timed.description()) .tags(timed.extraTags()) .tags(tagsBasedOnJoinpoint.apply(pjp)) .publishPercentileHistogram(timed.histogram()) .publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles()) .register(registry)); } } }
private void record(TimingSampleContext timingContext, HttpServletResponse response, HttpServletRequest request, Object handlerObject, Throwable e) { for (Timed timedAnnotation : timingContext.timedAnnotations) { timingContext.timerSample.stop(Timer.builder(timedAnnotation, metricName) .tags(tagsProvider.httpRequestTags(request, response, handlerObject, e)) .register(registry)); } if (timingContext.timedAnnotations.isEmpty() && autoTimeRequests) { timingContext.timerSample.stop(Timer.builder(metricName) .tags(tagsProvider.httpRequestTags(request, response, handlerObject, e)) .register(registry)); } for (LongTaskTimer.Sample sample : timingContext.longTaskTimerSamples) { sample.stop(); } }
@Override public void onError(Throwable e) { if (done) { this.malformedSourceCounter.increment(); Operators.onErrorDropped(e, actual.currentContext()); return; } done = true; //we don't record the time between last onNext and onError, // because it would skew the onNext count by one //register a timer for that particular exception Timer timer = subscribeToErrorTimerFactory.apply(e); //record error termination this.subscribeToTerminateSample.stop(timer); actual.onError(e); }
@Override public void onError(Throwable e) { if (done) { this.malformedSourceCounter.increment(); Operators.onErrorDropped(e, actual.currentContext()); return; } done = true; //register a timer for that particular exception Timer timer = subscribeToErrorTimerFactory.apply(e); //record error termination this.subscribeToTerminateSample.stop(timer); actual.onError(e); }
@Override public void onClose(final Status status, final Metadata metadata) { this.timerSample.stop(this.timerFunction.apply(status.getCode())); super.onClose(status, metadata); }
protected Object profileMethod(ProceedingJoinPoint pjp) throws Throwable { Timer.Sample sample = Timer.start(meterRegistry); try { return pjp.proceed(); } finally { sample.stop(meterRegistry.timer(MetricsListener.METRIC_NAME, Arrays.asList(// new ImmutableTag("context", getStepIdentifier()), // new ImmutableTag("method", ClassUtils.getShortName(pjp.getTarget().getClass()) + "." + pjp.getSignature().getName())))); } }
@Override public void close(final Status status, final Metadata responseHeaders) { this.timerSample.stop(this.timerFunction.apply(status.getCode())); super.close(status, responseHeaders); }
@Override public long stop() { return delegate.stop(timer); } }
protected void handleDoneEvent(AbstractExchangeEvent doneEvent) { String name = namingStrategy.getName(doneEvent.getExchange(), doneEvent.getExchange().getFromEndpoint()); Tags tags = namingStrategy.getTags(doneEvent, doneEvent.getExchange().getFromEndpoint()); // Would have preferred LongTaskTimer, but you cannot set the FAILED_TAG once it is registered Timer.Sample sample = (Timer.Sample) doneEvent.getExchange().removeProperty("eventTimer:" + name); if (sample != null) { sample.stop(getMeterRegistry().timer(name, tags)); } }
public void onExchangeDone(Exchange exchange) { Timer.Sample sample = (Timer.Sample) exchange.removeProperty(propertyName(exchange)); if (sample != null) { Timer timer = Timer.builder(namingStrategy.getName(route)) .tags(namingStrategy.getTags(route, exchange)) .description(route.getDescription()) .register(meterRegistry); sample.stop(timer); } }
@Test @DisplayName("record with stateful Sample instance") default void recordWithSample(MeterRegistry registry) { Timer timer = registry.timer("myTimer"); Timer.Sample sample = Timer.start(registry); clock(registry).add(10, TimeUnit.NANOSECONDS); sample.stop(timer); clock(registry).add(step()); assertAll(() -> assertEquals(1L, timer.count()), () -> assertEquals(10, timer.totalTime(TimeUnit.NANOSECONDS), 1.0e-12)); }
@Override public void nodeProcessingDone() { super.nodeProcessingDone(); Timer timer = Timer.builder(namingStrategy.getName(route, getNode())) .tags(namingStrategy.getTags(route, getNode())) .description(getNode().getDescriptionText()) .register(meterRegistry); sample.stop(timer); }
private void on(final State to) { final State from = state.getAndSet(to); final Sample last = sample.getAndSet(start(registry)); if (from != CLOSED) { last.stop(registry.timer(metricName, tags(from))); } }
@Override public void onComplete() { if (done) { this.malformedSourceCounter.increment(); return; } done = true; this.subscribeToTerminateSample.stop(subscribeToCompleteTimer); actual.onComplete(); }
@Override protected void doProcess(Exchange exchange, MicrometerEndpoint endpoint, Timer timer) { String propertyName = getPropertyName(timer.getId().getName()); Timer.Sample sample = getTimerSampleFromExchange(exchange, propertyName); sample.stop(timer); exchange.removeProperty(propertyName); }
protected Object profileMethod(ProceedingJoinPoint pjp) throws Throwable { Timer.Sample sample = Timer.start(meterRegistry); try { return pjp.proceed(); } finally { sample.stop(meterRegistry.timer(MetricsListener.METRIC_NAME, Arrays.asList(// new ImmutableTag("context", getStepIdentifier()), // new ImmutableTag("method", ClassUtils.getShortName(pjp.getTarget().getClass()) + "." + pjp.getSignature().getName())))); } }