Quarkus extension that integrates SmallRye Metrics with MicroProfile Metrics for application monitoring and observability
—
Core runtime classes for metrics metadata handling, factory integration, read-only counter implementations, and build-time processing.
Transfer object for metric metadata between build-time and runtime processing.
/**
* Wrapper for passing metric metadata from deployment to runtime
*/
public class MetadataHolder {
/** Get the metric name */
public String getName();
/** Set the metric name */
public void setName(String name);
/** Get the metric type */
public MetricType getMetricType();
/** Set the metric type */
public void setMetricType(MetricType metricType);
/** Get the metric description */
public String getDescription();
/** Set the metric description */
public void setDescription(String description);
/** Get the display name */
public String getDisplayName();
/** Set the display name */
public void setDisplayName(String displayName);
/** Get the metric unit */
public String getUnit();
/** Set the metric unit */
public void setUnit(String unit);
/** Create MetadataHolder from MicroProfile Metrics Metadata */
public static MetadataHolder from(Metadata metadata);
/** Convert back to MicroProfile Metrics Metadata */
public Metadata toMetadata();
}Usage Example:
import io.quarkus.smallrye.metrics.runtime.MetadataHolder;
import org.eclipse.microprofile.metrics.Metadata;
import org.eclipse.microprofile.metrics.MetricType;
// Convert from MP Metrics Metadata
Metadata mpMetadata = Metadata.builder()
.withName("my_counter")
.withType(MetricType.COUNTER)
.withDescription("Counts something important")
.build();
MetadataHolder holder = MetadataHolder.from(mpMetadata);
// Convert back to MP Metrics
Metadata converted = holder.toMetadata();Transfer object for metric tags between build-time and runtime processing.
/**
* Wrapper for passing metric tags from deployment to runtime
*/
public class TagHolder {
/** Get the tag name */
public String getName();
/** Set the tag name */
public void setName(String name);
/** Get the tag value */
public String getValue();
/** Set the tag value */
public void setValue(String value);
/** Create TagHolder from MicroProfile Metrics Tag */
public static TagHolder from(Tag tag);
/** Convert back to MicroProfile Metrics Tag */
public Tag toTag();
}Usage Example:
import io.quarkus.smallrye.metrics.runtime.TagHolder;
import org.eclipse.microprofile.metrics.Tag;
// Convert from MP Metrics Tag
Tag mpTag = new Tag("environment", "production");
TagHolder holder = TagHolder.from(mpTag);
// Convert back to MP Metrics
Tag converted = holder.toTag();Implementation of Quarkus MetricsFactory for SmallRye Metrics integration.
/**
* Implementation of Quarkus MetricsFactory for SmallRye Metrics
*/
public class SmallRyeMetricsFactory implements MetricsFactory {
/** Check if the metrics system supports the named metrics system */
public boolean metricsSystemSupported(String name);
/** Create a metric builder for the specified type */
public MetricBuilder builder(String name, MetricsFactory.Type type);
}
/**
* Internal metric builder implementation
*/
static class SmallRyeMetricBuilder implements MetricsFactory.MetricBuilder {
/** Set the metric unit */
public MetricBuilder unit(String unit);
/** Add a tag to the metric */
public MetricBuilder tag(String key, String value);
/** Set the metric description */
public MetricBuilder description(String description);
/** Build a counter metric with supplier function */
public void buildCounter(Supplier<Number> countFunction);
/** Build a counter metric with object and function */
public <T, R extends Number> void buildCounter(T obj, Function<T, R> countFunction);
/** Build a gauge metric with supplier function */
public void buildGauge(Supplier<Number> gaugeFunction);
/** Build a gauge metric with object and function */
public <T, R extends Number> void buildGauge(T obj, Function<T, R> gaugeFunction);
/** Build a timer metric and return time recorder */
public TimeRecorder buildTimer();
/** Build a timer metric wrapping a Runnable */
public Runnable buildTimer(Runnable f);
/** Build a timer metric wrapping a Callable */
public <T> Callable<T> buildTimer(Callable<T> f);
/** Build a timer metric wrapping a Supplier */
public <T> Supplier<T> buildTimer(Supplier<T> f);
}Usage Example:
import io.quarkus.smallrye.metrics.runtime.SmallRyeMetricsFactory;
import io.quarkus.runtime.metrics.MetricsFactory;
SmallRyeMetricsFactory factory = new SmallRyeMetricsFactory();
// Check if system is supported
boolean supported = factory.metricsSystemSupported("smallrye-metrics");
// Create a metric builder
MetricBuilder builder = factory.builder("my_metric", MetricsFactory.Type.APPLICATION);Internal utility class for JAX-RS metrics collection and REST endpoint metric creation.
/**
* Internal utility class for JAX-RS metrics collection
* Package-private class used by filter implementations
*/
final class FilterUtil {
/** Complete a request and record metrics based on success/failure */
static void finishRequest(Long start, Class<?> resourceClass, String methodName,
Class<?>[] parameterTypes, Supplier<Boolean> wasSuccessful);
/** Create metrics for a REST endpoint if they don't already exist */
static void maybeCreateMetrics(Class<?> resourceClass, Method resourceMethod);
/** Generate MetricID for REST endpoint metrics */
static MetricID getMetricID(Class<?> resourceClass, String methodName,
Class<?>[] parameterTypes, boolean requestWasSuccessful);
}Usage Example:
// This class is used internally by QuarkusRestMetricsFilter and QuarkusRestEasyMetricsFilter
// Application code typically doesn't interact with it directly
// Example usage in filters:
FilterUtil.maybeCreateMetrics(MyResource.class, method);
FilterUtil.finishRequest(startTime, MyResource.class, "getUsers",
new Class[0], () -> true);
// Generates metric names like:
// - REST.request (for successful requests)
// - REST.request.unmappedException.total (for failed requests)
// With tags: class=com.example.MyResource, method=getUsersAbstract base class for implementing read-only counter metrics.
/**
* Helper abstract class for implementing read-only counters
* Implements org.eclipse.microprofile.metrics.Counter
*/
public abstract class GetCountOnlyCounter implements Counter {
/** Get the current count value - must be implemented by subclasses */
public abstract long getCount();
/** Increment counter - throws IllegalStateException (read-only) */
public void inc();
/** Increment counter by specified amount - throws IllegalStateException (read-only) */
public void inc(long n);
}Usage Example:
import io.quarkus.smallrye.metrics.runtime.GetCountOnlyCounter;
// Implementation of a read-only counter
public class MyReadOnlyCounter extends GetCountOnlyCounter {
private final AtomicLong value = new AtomicLong(0);
@Override
public long getCount() {
return value.get();
}
// inc() and inc(long) will throw IllegalStateException
}Build-time recorder for metrics configuration and registration. This class handles deployment-time processing for optimal native compilation.
/**
* Build-time recorder for metrics configuration
* Annotated with @Recorder for Quarkus build-time processing
*/
@Recorder
public class SmallRyeMetricsRecorder {
/** Create metrics handler with specified path */
public SmallRyeMetricsHandler handler(String metricsPath);
/** Register vendor-specific metrics */
public void registerVendorMetrics();
/** Register base JVM metrics */
public void registerBaseMetrics();
/** Register Micrometer-compatible JVM metrics */
public void registerMicrometerJvmMetrics(ShutdownContext shutdown);
/** Register metrics from bean and member information */
public void registerMetrics(BeanInfo beanInfo, MemberInfo memberInfo);
/** Register individual metric with metadata and tags */
public void registerMetric(/* multiple overloads for different metric types */);
/** Register metrics via factory consumer */
public void registerMetrics(Consumer<MetricsFactory> consumer);
/** Initialize metric registries */
public void createRegistries(BeanContainer container);
/** Cleanup registries at shutdown */
public void dropRegistriesAtShutdown(ShutdownContext shutdownContext);
}Usage Example:
// This class is primarily used by the Quarkus deployment processor
// Application code typically doesn't interact with it directly
@BuildStep
void registerApplicationMetrics(SmallRyeMetricsRecorder recorder) {
// Build-time metric registration
recorder.registerVendorMetrics();
recorder.registerBaseMetrics();
}// From MicroProfile Metrics API
interface Metadata {
String getName();
MetricType getType();
String getDescription();
String getDisplayName();
String getUnit();
}
class Tag {
Tag(String name, String value);
String getTagName();
String getTagValue();
}
enum MetricType {
COUNTER, GAUGE, TIMER, HISTOGRAM, METER, CONCURRENT_GAUGE
}
// From Quarkus Runtime Metrics
interface MetricsFactory {
boolean metricsSystemSupported(String name);
MetricBuilder builder(String name, Type type);
enum Type {
APPLICATION, BASE, VENDOR
}
}Install with Tessl CLI
npx tessl i tessl/maven-io-quarkus--quarkus-smallrye-metrics