Top Description Annotations
module org.eclipse.microprofile.metrics

Package org.eclipse.microprofile.metrics.annotation

Annotations
@Version:5.1.0

This package contains the annotations used for MicroProfile Metrics.

Metric Annotation

The Metric annotation is used to provide metadata for the metric being injected. If a metric with the same name exists in the MetricRegistry, the metric is returned. Otherwise, a new metric is registered into the MetricRegistry along with the metadata provided by the @Metric annotation.

For example,


    @Inject
    @Metric(name="histogram", description="The description")
    public Histogram histogram;

Interceptor Bindings

MicroProfile Metrics provides interceptor bindings which can be used to instrument an application: @Counted, @Gauge and @Timed

An example using @Counted,


    @Counted (name="visitorCount",
        description="The number of visitors to the application")
    public void visit () {
        ...
    }

An example using @Gauge,


    @Gauge(name = "queueSize")
    public int getQueueSize() {
        return queue.size;
    }

RegistryScope annotation

The RegistryScope is used to identify which MetricRegistry (Application, Base, Vendor or a user-defined scope) should be injected. Injecting a MetricRegistry without a RegistryScope annotation gives the application-scoped MetricRegistry.


     @Inject
     @RegistryScope(scope=MetricRegistry.APPLICATION_SCOPE)
     MetricRegistry appRegistry;

RegistryType CDI Qualifier

This is DEPRECATED. Please use RegistryScope instead. The RegistryType is used to identify which MetricRegistry (Application, Base, or Vendor) should be injected. Injecting a MetricRegistry without a RegistryType annotation gives the application-scoped MetricRegistry.


     @Inject
     @RegistryType(type=MetricRegistry.Type.BASE)
     MetricRegistry baseRegistry;

Annotation Summary

Modifier and TypeAnnotation and Description
public @interface
Counted

An annotation for marking a method, constructor, or class as counted.

public @interface
Gauge

An annotation for marking a method or field as a gauge.

public @interface
Metric

An annotation requesting that a metric be injected or registered.

public @interface
RegistryScope

Specifies the scope of Metric Registry to inject.

public @interface
RegistryType

Deprecated As of rlease 5.0, please use RegistryScope instead
Qualifies the type of Metric Registry to inject.
public @interface
Timed

An annotation for marking a method, constructor, or class as timed.