Annotation Interface Counted


An annotation for marking a method, constructor, or class as counted. The metric will be registered in the application MetricRegistry.

Given a method annotated with @Counted like this:


     @Counted(name = "fancyName")
     public String fancyName(String name) {
         return "Sir Captain " + name;
     }
 
A counter with the fully qualified class name + fancyName will be created and each time the #fancyName(String) method is invoked, the counter will be marked. Similarly, the same applies for a constructor annotated with counted.

Given a class annotated with @Counted like this:


     @Counted
     public class CounterBean {
         public void countMethod1() {}
         public void countMethod2() {}
     }
 
A counter for the defining class will be created for each of the constructors/methods. Each time the constructor/method is invoked, the respective counter will be marked. The counter value will only monotonically increase.

Note: the default behaviour has changed in MicroProfile Metrics 2.0. To get the old @Counted(monotonic=false) behavior, see @ConcurrentGauge

This annotation will throw an IllegalStateException if the constructor/method is invoked, but the metric no longer exists in the MetricRegistry.
  • Element Details

    • name

      String name
      Returns:
      The name of the counter.
      Default:
      ""
    • tags

      String[] tags
      Returns:
      The tags of the counter. Each String tag must be in the form of 'key=value'. If the input is empty or does not contain a '=' sign, the entry is ignored.
      See Also:
      Default:
      {}
    • absolute

      boolean absolute
      Returns:
      If true, use the given name as an absolute name. If false (default), use the given name relative to the annotated class. When annotating a class, this must be false.
      Default:
      false
    • displayName

      String displayName
      Returns:
      The display name of the counter.
      See Also:
      Default:
      ""
    • description

      String description
      Returns:
      The description of the counter.
      See Also:
      Default:
      ""
    • unit

      String unit
      Returns:
      The unit of the counter. By default, the value is MetricUnits.NONE.
      See Also:
      Default:
      "none"
    • reusable

      boolean reusable
      Denotes if this metric instance can be reused by multiple registrations.
      Returns:
      false if not reusable, true otherwise
      Since:
      Metrics 1.1
      Default:
      false