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));
}
}
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);
}
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();
}
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();
});
}
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();
}
Aggregations