Quarkus extension that integrates SmallRye Metrics with MicroProfile Metrics for application monitoring and observability
—
JAX-RS filters and Vert.x handlers for automatic metrics collection from REST endpoints and metrics endpoint exposure.
JAX-RS response filter for automatic metrics collection from Quarkus REST endpoints.
/**
* JAX-RS response filter for Quarkus REST metrics collection
* Automatically collects timing and request count metrics for REST endpoints
*/
@ServerResponseFilter
public class QuarkusRestMetricsFilter {
// Filter is automatically applied to Quarkus REST endpoints
// No public methods - integration is annotation-based
}Usage Example:
// Filter is automatically applied when the extension is present
// No explicit configuration needed - metrics are collected automatically
@Path("/api")
public class MyResource {
@GET
@Path("/users")
public List<User> getUsers() {
// Metrics automatically collected:
// - REST.request timer (execution time)
// - Request count by status code
return userService.getAllUsers();
}
}JAX-RS filter for automatic metrics collection from RESTEasy Classic endpoints.
/**
* JAX-RS filter for RESTEasy metrics collection
* Implements both request and response filtering
*/
public class QuarkusRestEasyMetricsFilter
implements ContainerRequestFilter, ContainerResponseFilter {
/** Filter incoming requests to start timing */
public void filter(ContainerRequestContext requestContext);
/** Filter outgoing responses to complete timing and record metrics */
public void filter(
ContainerRequestContext requestContext,
ContainerResponseContext responseContext
);
}Usage Example:
// Filter is automatically applied when using RESTEasy Classic
// Metrics are collected for all JAX-RS endpoints
@Path("/api/v1")
public class LegacyResource {
@GET
@Path("/products")
public Response getProducts() {
// Metrics automatically collected:
// - Request timing
// - Response status codes
// - Request counts
return Response.ok(productService.getAllProducts()).build();
}
}Vert.x handler for exposing metrics endpoint via HTTP.
/**
* Vert.x handler for metrics endpoint exposure
* Handles HTTP requests to the metrics endpoint
*/
public class SmallRyeMetricsHandler implements Handler<RoutingContext> {
/** Configure the metrics endpoint path */
public void setMetricsPath(String metricsPath);
/** Handle incoming HTTP requests for metrics */
public void handle(RoutingContext routingContext);
}Usage Example:
import io.quarkus.smallrye.metrics.runtime.SmallRyeMetricsHandler;
import io.vertx.ext.web.RoutingContext;
// Typically configured by the extension deployment processor
SmallRyeMetricsHandler handler = new SmallRyeMetricsHandler();
handler.setMetricsPath("/custom-metrics");
// Handler processes requests to metrics endpoint
// Returns metrics in Prometheus format by default
// Supports JSON format via Accept: application/json headerThe extension automatically collects metrics for JAX-RS endpoints:
// Metrics automatically created:
// - REST.request timer per endpoint
// - Request counts by HTTP status code
// - Response time percentiles
// - Exception counts
// Timer naming pattern:
// REST.request.{class}.{method}
// Tags: class, method, uri, status
// Example metric names:
// REST.request.com_example_UserResource_getUsers_GET
// REST.request.com_example_ProductResource_createProduct_POSTMetric Tags:
// Tags applied to REST metrics:
Tag.of("class", "com.example.UserResource")
Tag.of("method", "getUsers")
Tag.of("uri", "/api/users")
Tag.of("status", "200")The /q/metrics endpoint (or custom path) exposes all metrics:
// Default endpoint: /q/metrics
// Configurable via: quarkus.smallrye-metrics.path
// Response formats:
// - Prometheus format (default, text/plain)
// - JSON format (Accept: application/json)
// Example Prometheus output:
// # TYPE REST_request_total counter
// REST_request_total{class="UserResource",method="getUsers",status="200"} 42
//
// # TYPE REST_request_seconds summary
// REST_request_seconds{class="UserResource",method="getUsers",quantile="0.5"} 0.123// Handler is registered by the deployment processor
// Typically at build time via SmallRyeMetricsRecorder
// Example registration (internal):
Router router = Router.router(vertx);
SmallRyeMetricsHandler handler = recorder.handler("/q/metrics");
router.get("/q/metrics").handler(handler);The metrics handler processes requests:
scope=application, scope=base, scope=vendor)// Enable/disable JAX-RS metrics collection
// quarkus.smallrye-metrics.jaxrs.enabled=true|false
// When disabled, REST endpoint metrics are not collected
// Application and base metrics remain available// Default metrics path: /q/metrics
// Custom path via configuration:
// quarkus.smallrye-metrics.path=/custom-metrics
SmallRyeMetricsHandler handler = new SmallRyeMetricsHandler();
handler.setMetricsPath("/custom-metrics");// JAX-RS Types
interface ContainerRequestFilter {
void filter(ContainerRequestContext requestContext);
}
interface ContainerResponseFilter {
void filter(
ContainerRequestContext requestContext,
ContainerResponseContext responseContext
);
}
// Vert.x Types
interface Handler<T> {
void handle(T event);
}
class RoutingContext {
HttpServerRequest request();
HttpServerResponse response();
void next();
void fail(int statusCode);
}Install with Tessl CLI
npx tessl i tessl/maven-io-quarkus--quarkus-smallrye-metrics