Search in sources :

Example 21 with Tags

use of io.micrometer.core.instrument.Tags in project snow-owl by b2ihealthcare.

the class MonitoredRequest method execute.

@Override
public R execute(ServiceProvider context) {
    final MeterRegistry registry = context.service(MeterRegistry.class);
    final Sample responseTimeSample = Timer.start(registry);
    try {
        return next(context);
    } finally {
        final Tags tags = Tags.of("context", getContextId());
        tags.and("context", DEFAULT_CONTEXT_ID);
        final long responseTime = responseTimeSample.stop(registry.timer("response_time", tags));
        final Map<String, Object> additionalInfo = Map.of("metrics", Map.of("responseTime", TimeUnit.NANOSECONDS.toMillis(responseTime)));
        LOG.info(toJson(context, next(), additionalInfo));
    }
}
Also used : Sample(io.micrometer.core.instrument.Timer.Sample) Tags(io.micrometer.core.instrument.Tags) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 22 with Tags

use of io.micrometer.core.instrument.Tags in project webpieces by deanhiller.

the class TransactionHelper method monitorTransactionTime.

private void monitorTransactionTime(String transactionName, long begin) {
    String requestPath = (String) Context.get(ContextKey.REQUEST_PATH.toString());
    if (requestPath == null || requestPath.isBlank()) {
        requestPath = "unknown";
    }
    Tags transactionTags = Tags.of(DatabaseTransactionTags.EXECUTION_ID, transactionName, DatabaseTransactionTags.REQUEST, requestPath);
    meterRegistry.timer(DatabaseMetric.EXECUTION_TIME.getDottedMetricName(), transactionTags).record(System.currentTimeMillis() - begin, TimeUnit.MILLISECONDS);
}
Also used : Tags(io.micrometer.core.instrument.Tags) DatabaseTransactionTags(org.webpieces.plugin.hibernate.metrics.DatabaseTransactionTags)

Example 23 with Tags

use of io.micrometer.core.instrument.Tags in project reactor-core by reactor.

the class SchedulerMetricDecorator method apply.

@Override
public synchronized ScheduledExecutorService apply(Scheduler scheduler, ScheduledExecutorService service) {
    // this is equivalent to `toString`, a detailed name like `parallel("foo", 3)`
    String schedulerName = Scannable.from(scheduler).scanOrDefault(Attr.NAME, scheduler.getClass().getName());
    // we hope that each NAME is unique enough, but we'll differentiate by Scheduler
    String schedulerId = seenSchedulers.computeIfAbsent(scheduler, s -> {
        int schedulerDifferentiator = this.schedulerDifferentiator.computeIfAbsent(schedulerName, k -> new AtomicInteger(0)).getAndIncrement();
        return (schedulerDifferentiator == 0) ? schedulerName : schedulerName + "#" + schedulerDifferentiator;
    });
    // we now want an executorId unique to a given scheduler
    String executorId = schedulerId + "-" + executorDifferentiator.computeIfAbsent(scheduler, key -> new AtomicInteger(0)).getAndIncrement();
    Tags tags = Tags.of(TAG_SCHEDULER_ID, schedulerId);
    class MetricsRemovingScheduledExecutorService extends DelegatingScheduledExecutorService {

        MetricsRemovingScheduledExecutorService() {
            super(ExecutorServiceMetrics.monitor(registry, service, executorId, tags));
        }

        @Override
        public List<Runnable> shutdownNow() {
            removeMetrics();
            return super.shutdownNow();
        }

        @Override
        public void shutdown() {
            removeMetrics();
            super.shutdown();
        }

        void removeMetrics() {
            Search.in(registry).tag("name", executorId).meters().forEach(registry::remove);
        }
    }
    return new MetricsRemovingScheduledExecutorService();
}
Also used : Metrics(reactor.util.Metrics) Tags(io.micrometer.core.instrument.Tags) ExecutorServiceMetrics(io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics) Disposable(reactor.core.Disposable) Scannable(reactor.core.Scannable) BiFunction(java.util.function.BiFunction) HashMap(java.util.HashMap) List(java.util.List) Attr(reactor.core.Scannable.Attr) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Search(io.micrometer.core.instrument.search.Search) WeakHashMap(java.util.WeakHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tags(io.micrometer.core.instrument.Tags)

Example 24 with Tags

use of io.micrometer.core.instrument.Tags in project reactor-core by reactor.

the class FluxMetricsFuseableTest method subscribeToCompleteFuseable.

@Test
public void subscribeToCompleteFuseable() {
    Flux<String> source = Flux.just(1).doOnNext(v -> {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }).map(i -> "foo");
    StepVerifier.create(new FluxMetricsFuseable<>(source)).expectFusion(// just only supports SYNC
    Fuseable.SYNC).expectNext("foo").verifyComplete();
    Timer stcCompleteTimer = registry.find(REACTOR_DEFAULT_NAME + METER_FLOW_DURATION).tags(Tags.of(TAG_ON_COMPLETE)).timer();
    Timer stcErrorTimer = registry.find(REACTOR_DEFAULT_NAME + METER_FLOW_DURATION).tags(Tags.of(TAG_ON_ERROR)).timer();
    Timer stcCancelTimer = registry.find(REACTOR_DEFAULT_NAME + METER_FLOW_DURATION).tags(Tags.of(TAG_CANCEL)).timer();
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(stcCompleteTimer.max(TimeUnit.MILLISECONDS)).as("subscribe to complete timer").isGreaterThanOrEqualTo(100);
        softly.assertThat(stcErrorTimer).as("subscribe to error timer lazily registered").isNull();
        softly.assertThat(stcCancelTimer).as("subscribe to cancel timer").isNull();
    });
}
Also used : Metrics(reactor.util.Metrics) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SoftAssertions(org.assertj.core.api.SoftAssertions) StepVerifier(reactor.test.StepVerifier) MockClock(io.micrometer.core.instrument.MockClock) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicReference(java.util.concurrent.atomic.AtomicReference) Timer(io.micrometer.core.instrument.Timer) Duration(java.time.Duration) Counter(io.micrometer.core.instrument.Counter) Tags(io.micrometer.core.instrument.Tags) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Clock(io.micrometer.core.instrument.Clock) SimpleConfig(io.micrometer.core.instrument.simple.SimpleConfig) TAG_ON_COMPLETE_EMPTY(reactor.core.publisher.FluxMetrics.TAG_ON_COMPLETE_EMPTY) FluxMetrics(reactor.core.publisher.FluxMetrics) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Fuseable(reactor.core.Fuseable) DistributionSummary(io.micrometer.core.instrument.DistributionSummary) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Timer(io.micrometer.core.instrument.Timer) Test(org.junit.jupiter.api.Test)

Example 25 with Tags

use of io.micrometer.core.instrument.Tags in project reactor-core by reactor.

the class FluxMetricsFuseableTest method splitMetricsOnNameFuseable.

@Test
public void splitMetricsOnNameFuseable() {
    final Flux<Integer> unnamedSource = Flux.just(0).map(v -> 100 / v);
    final Flux<Integer> namedSource = Flux.range(1, 40).map(i -> 100 / (40 - i)).name("foo");
    final Flux<Integer> unnamed = new FluxMetricsFuseable<>(unnamedSource).onErrorResume(e -> Mono.empty());
    final Flux<Integer> named = new FluxMetricsFuseable<>(namedSource).onErrorResume(e -> Mono.empty());
    Mono.when(unnamed, named).block();
    Timer unnamedMeter = registry.find(REACTOR_DEFAULT_NAME + METER_FLOW_DURATION).tags(Tags.of(TAG_ON_ERROR)).timer();
    Timer namedMeter = registry.find("foo" + METER_FLOW_DURATION).tags(Tags.of(TAG_ON_ERROR)).timer();
    assertThat(unnamedMeter).isNotNull();
    assertThat(unnamedMeter.count()).isOne();
    assertThat(namedMeter).isNotNull();
    assertThat(namedMeter.count()).isOne();
}
Also used : Metrics(reactor.util.Metrics) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SoftAssertions(org.assertj.core.api.SoftAssertions) StepVerifier(reactor.test.StepVerifier) MockClock(io.micrometer.core.instrument.MockClock) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicReference(java.util.concurrent.atomic.AtomicReference) Timer(io.micrometer.core.instrument.Timer) Duration(java.time.Duration) Counter(io.micrometer.core.instrument.Counter) Tags(io.micrometer.core.instrument.Tags) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Clock(io.micrometer.core.instrument.Clock) SimpleConfig(io.micrometer.core.instrument.simple.SimpleConfig) TAG_ON_COMPLETE_EMPTY(reactor.core.publisher.FluxMetrics.TAG_ON_COMPLETE_EMPTY) FluxMetrics(reactor.core.publisher.FluxMetrics) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Fuseable(reactor.core.Fuseable) DistributionSummary(io.micrometer.core.instrument.DistributionSummary) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Timer(io.micrometer.core.instrument.Timer) Test(org.junit.jupiter.api.Test)

Aggregations

Tags (io.micrometer.core.instrument.Tags)26 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)10 Test (org.junit.jupiter.api.Test)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 Timer (io.micrometer.core.instrument.Timer)6 Clock (io.micrometer.core.instrument.Clock)5 Counter (io.micrometer.core.instrument.Counter)5 DistributionSummary (io.micrometer.core.instrument.DistributionSummary)5 TimeUnit (java.util.concurrent.TimeUnit)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 MockClock (io.micrometer.core.instrument.MockClock)4 SimpleConfig (io.micrometer.core.instrument.simple.SimpleConfig)4 Duration (java.time.Duration)4 Scannable (reactor.core.Scannable)4 Metrics (reactor.util.Metrics)4 Sample (io.micrometer.core.instrument.Timer.Sample)3 Vertx (io.vertx.core.Vertx)3 File (java.io.File)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatCode (org.assertj.core.api.Assertions.assertThatCode)3