Package org.eclipse.microprofile.metrics.annotation


@Version("2.3") package org.eclipse.microprofile.metrics.annotation

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, @Metered, @Timed, @SimplyTimed and @ConcurrentGauge.

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;
     }
 
 

CDI Qualifier

The RegistryType is used to identify which MetricRegistry (Application, Base, or Vendor) should be injected. By default, no RegistryType will inject the application MetricRegistry.

 
      @Inject
      @RegistryType(type=MetricRegistry.Type.BASE)
      MetricRegistry baseRegistry;
 
 
  • Annotation Interfaces
    Class
    Description
    An annotation for marking a method, constructor, or class as concurrent gauged.
    An annotation for marking a method, constructor, or class as counted.
    An annotation for marking a method or field as a gauge.
    An annotation for marking a method, constructor, or class as metered.
    An annotation requesting that a metric be injected or registered.
    Qualifies the type of Metric Registry to inject.
    An annotation for marking a method, constructor, or class as simply timed.
    An annotation for marking a method, constructor, or class as timed.