@Benchmark public int sumTimedWithSample() { Timer.Sample sample = Timer.start(registry); int sum = sum(); sample.stop(timer); return sum; }
@Override public void onSubscribe(Subscription s) { if (Operators.validate(this.s, s)) { this.subscribedCounter.increment(); this.subscribeToTerminateSample = Timer.start(clock); if (s instanceof Fuseable.QueueSubscription) { //noinspection unchecked this.qs = (Fuseable.QueueSubscription<T>) s; } this.s = s; actual.onSubscribe(this); } }
@Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { Sample sample = Timer.start(meterRegistry); return chain.filter(exchange).doOnSuccessOrError((aVoid, ex) -> { endTimerRespectingCommit(exchange, sample); }); }
@Override public void onSubscribe(Subscription s) { if (Operators.validate(this.s, s)) { this.subscribedCounter.increment(); this.subscribeToTerminateSample = Timer.start(clock); this.lastNextEventNanos = clock.monotonicTime(); if (s instanceof Fuseable.QueueSubscription) { //noinspection unchecked this.qs = (Fuseable.QueueSubscription<T>) s; } this.s = s; actual.onSubscribe(this); } }
Sample start() { return Timer.start(meterRegistry); }
/** * Creates a new delegating ServerCall that will wrap the given server call to collect metrics. * * @param delegate The original call to wrap. * @param registry The registry to save the metrics to. * @param responseCounter The counter for incoming responses. * @param timerFunction A function that will return a timer for a given status code. */ public MetricCollectingServerCall(final ServerCall<Q, A> delegate, final MeterRegistry registry, final Counter responseCounter, final Function<Code, Timer> timerFunction) { super(delegate); this.responseCounter = responseCounter; this.timerFunction = timerFunction; this.timerSample = Timer.start(registry); }
/** * Creates a new delegating ClientCallListener that will wrap the given client call listener to collect metrics. * * @param delegate The original call to wrap. * @param registry The registry to save the metrics to. * @param responseCounter The counter for incoming responses. * @param timerFunction A function that will return a timer for a given status code. */ public MetricCollectingClientCallListener( final ClientCall.Listener<A> delegate, final MeterRegistry registry, final Counter responseCounter, final Function<Code, Timer> timerFunction) { super(delegate); this.responseCounter = responseCounter; this.timerFunction = timerFunction; this.timerSample = Timer.start(registry); }
public Sample start(MeterRegistry registry) { if (longTask) { LongTaskTimer.Sample sample = LongTaskTimer.builder(name) .description(description) .tags(tags) .register(registry) .start(); return () -> sample.stop(); } Timer.Sample sample = Timer.start(registry); Timer timer = Timer.builder(name) .description(description) .tags(tags) .publishPercentileHistogram(histogram) .publishPercentiles(percentiles) .register(registry); return () -> sample.stop(timer); }
@Override public SampleFacade start() { return new MicroSample(Timer.start(this.meterRegistry)); }
private TimingContext startAndAttachTimingContext(HttpServletRequest request) { Timer.Sample timerSample = Timer.start(this.registry); TimingContext timingContext = new TimingContext(timerSample); timingContext.attachTo(request); return timingContext; }
public MicrometerMessageHistory(MeterRegistry meterRegistry, Route route, NamedNode namedNode, MicrometerMessageHistoryNamingStrategy namingStrategy, long timestamp) { super(route.getId(), namedNode, timestamp); this.meterRegistry = meterRegistry; this.route = route; this.namingStrategy = namingStrategy; this.sample = Timer.start(meterRegistry); }
@API(status = INTERNAL) MetricsCircuitBreakerListener(final MeterRegistry registry, final String metricName, final ImmutableList<Tag> defaultTags) { this.registry = registry; this.metricName = metricName; this.defaultTags = defaultTags; this.sample = new AtomicReference<>(start(registry)); }
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))); } }
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))); } }
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())))); } }
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())))); } }
void handleStart(Exchange exchange, MeterRegistry registry, String metricsName) { String propertyName = getPropertyName(metricsName); Timer.Sample sample = getTimerSampleFromExchange(exchange, propertyName); if (sample == null) { sample = Timer.start(registry); exchange.setProperty(propertyName, sample); } else { LOG.warn("Timer \"{}\" already running", metricsName); } }
TimingSampleContext(HttpServletRequest request, Object handlerObject) { timedAnnotations = annotations(handlerObject); timerSample = Timer.start(registry); longTaskTimerSamples = timedAnnotations.stream() .filter(Timed::longTask) .map(t -> LongTaskTimer.builder(t) .tags(tagsProvider.httpLongRequestTags(request, handlerObject)) .register(registry) .start()) .collect(Collectors.toList()); }
@Override public void onSubscribe(Subscription s) { if (Operators.validate(this.s, s)) { this.subscribedCounter.increment(); this.subscribeToTerminateSample = Timer.start(clock); if (s instanceof Fuseable.QueueSubscription) { //noinspection unchecked this.qs = (Fuseable.QueueSubscription<T>) s; } this.s = s; actual.onSubscribe(this); } }
@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)); }