All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.micrometer.runtime.binder.mpmetrics.ConcurrentGaugeInterceptor Maven / Gradle / Ivy

Go to download

Instrument the runtime and your application with dimensional metrics using Micrometer.

There is a newer version: 3.17.5
Show newest version
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.ConcurrentGauge;

import io.quarkus.arc.ArcInvocationContext;

@ConcurrentGauge
@Interceptor
@Priority(Interceptor.Priority.LIBRARY_BEFORE + 10)
class ConcurrentGaugeInterceptor {

    // Micrometer meter registry
    final MetricRegistryAdapter mpRegistry;

    ConcurrentGaugeInterceptor(MetricRegistryAdapter mpRegistry) {
        this.mpRegistry = mpRegistry;
    }

    @AroundConstruct
    Object cGaugeConstructor(ArcInvocationContext context) throws Exception {
        return cGauge(context, context.getConstructor().getDeclaringClass().getSimpleName());
    }

    @AroundInvoke
    Object cGaugeMethod(ArcInvocationContext context) throws Exception {
        return cGauge(context, context.getMethod().getName());
    }

    Object cGauge(ArcInvocationContext context, String methodName) throws Exception {
        ConcurrentGauge annotation = context.findIterceptorBinding(ConcurrentGauge.class);
        if (annotation != null) {
            MpMetadata metadata = new MpMetadata(annotation.name().replace("", methodName),
                    annotation.description().replace("", methodName),
                    annotation.unit(),
                    MetricType.CONCURRENT_GAUGE);

            ConcurrentGaugeImpl impl = mpRegistry.interceptorConcurrentGauge(metadata, annotation.tags());
            try {
                impl.inc();
                return context.proceed();
            } finally {
                impl.dec();
            }
        }
        return context.proceed();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy