Class Enumeration

  • All Implemented Interfaces:
    Collector.Describable

    public class Enumeration
    extends SimpleCollector<Enumeration.Child>
    implements Collector.Describable
    Enumeration metric, to track which of a set of states something is in. The first provided state will be the default.

    Example Enumeration:

     
       class YourClass {
         static final Enumeration taskState = Enumeration.build()
             .name("task_state").help("State of the task.")
             .states("stopped", "starting", "running")
             .register();
    
         void stop() {
              // Your code here.
              taskState.state("stopped")
         }
       }
     
     
    You can also use a Java Enum:
       class YourClass {
         public enum yourEnum {
           STOPPED,
           STARTING,
           RUNNING,
         }
         static final Enumeration taskState = Enumeration.build()
             .name("task_state").help("State of the task.")
             .states(yourEnum.class)
             .register();
    
         void stop() {
              // Your code here.
              taskState.state(yourEnum.STOPPED)
         }
       }
     }
     
    Since:
    0.10.0
    • Method Detail

      • build

        public static Enumeration.Builder build​(String name,
                                                String help)
        Return a Builder to allow configuration of a new Enumeration. Ensures required fields are provided.
        Parameters:
        name - The name of the metric
        help - The help string of the metric
      • state

        public void state​(String s)
        Set the state on the enum with no labels.
      • state

        public void state​(Enum e)
        Set the state on the enum with no labels.
      • get

        public String get()
        Get the value of the Enumeration.
      • describe

        public List<Collector.MetricFamilySamplesdescribe()
        Description copied from interface: Collector.Describable
        Provide a list of metric families this Collector is expected to return. These should exclude the samples. This is used by the registry to detect collisions and duplicate registrations. Usually custom collectors do not have to implement Describable. If Describable is not implemented and the CollectorRegistry was created with auto describe enabled (which is the case for the default registry) then Collector.collect() will be called at registration time instead of describe. If this could cause problems, either implement a proper describe, or if that's not practical have describe return an empty list.
        Specified by:
        describe in interface Collector.Describable