io.quarkus.micrometer.runtime.binder.mpmetrics.CountedInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-micrometer Show documentation
Show all versions of quarkus-micrometer Show documentation
Instrument the runtime and your application with dimensional metrics using Micrometer.
package io.quarkus.micrometer.runtime.binder.mpmetrics;
import jakarta.annotation.Priority;
import jakarta.interceptor.AroundConstruct;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import org.eclipse.microprofile.metrics.MetricType;
import org.eclipse.microprofile.metrics.annotation.Counted;
import io.quarkus.arc.ArcInvocationContext;
@SuppressWarnings("unused")
@Counted
@Interceptor
@Priority(Interceptor.Priority.LIBRARY_BEFORE + 10)
class CountedInterceptor {
// Micrometer meter registry
final MetricRegistryAdapter mpRegistry;
CountedInterceptor(MetricRegistryAdapter mpRegistry) {
this.mpRegistry = mpRegistry;
}
@AroundConstruct
Object countedConstructor(ArcInvocationContext context) throws Exception {
return increment(context, context.getConstructor().getDeclaringClass().getSimpleName());
}
@AroundInvoke
Object countedMethod(ArcInvocationContext context) throws Exception {
return increment(context, context.getMethod().getName());
}
Object increment(ArcInvocationContext context, String methodName) throws Exception {
Counted annotation = context.findIterceptorBinding(Counted.class);
if (annotation != null) {
MpMetadata metadata = new MpMetadata(annotation.name().replace("", methodName),
annotation.description().replace("", methodName),
annotation.unit(),
MetricType.COUNTER);
mpRegistry.interceptorCounter(metadata, annotation.tags()).inc();
}
return context.proceed();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy