Class MetricsFactory

java.lang.Object
de.iip_ecosphere.platform.support.metrics.MetricsFactory

public abstract class MetricsFactory extends Object
Generic access to Metering/Metrics. Requires an implementing plugin of type MetricsFactory or an active MetricsFactoryProviderDescriptor. Simplified interface akin to micrometer.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • MetricsFactory

      public MetricsFactory()
  • Method Details

    • getInstance

      public static MetricsFactory getInstance()
      Returns the Rest instance.
      Returns:
      the instance
    • setInstance

      public static void setInstance(MetricsFactory rest)
      Manually sets the instance. Shall not be needed, but may be required in some tests.
      Parameters:
      rest - the Rest instance
    • createRegistry

      public MeterRegistry createRegistry()
      Creates a default meter registry.
      Returns:
      the registry
    • createRegistry

      public MeterRegistry createRegistry(Object registry)
      Creates a meter registry. This method is a bit tricky as it implies a border crossing between abstraction and implementation. The actual type of registry may not fit to the registry type of the implementation, which we actually don't know here and, thus, cannot use. In some cases it is required to use this plugin as maven component and to exclude the contained implementation libray to make the types fit.
      Parameters:
      registry - something that the implementation shall use to create a registry from, e.g., a micrometer registry, may be null
      Returns:
      the registry
    • createRegistry

      protected abstract MeterRegistry createRegistry(Object registry, boolean warn)
      Creates a meter registry. This method is a bit tricky as it implies a border crossing between abstraction and implementation. The actual type of registry may not fit to the registry type of the implementation, which we actually don't know here and, thus, cannot use. In some cases it is required to use this plugin as maven component and to exclude the contained implementation libray to make the types fit.
      Parameters:
      registry - something that the implementation shall use to create a registry from, e.g., a micrometer registry, may be null
      warn - warn if the provided type does not match the implementation and a default is created instead
      Returns:
      the registry
    • createCounter

      public abstract Counter.CounterBuilder createCounter(String name)
      Starts building a counter by returning a counter builder.
      Parameters:
      name - the name of the counter
      Returns:
      the counter builder
    • createTimer

      public abstract Timer.TimerBuilder createTimer(String name)
      Starts building a timer by returning a timer builder.
      Parameters:
      name - the name of the timer
      Returns:
      the timer builder
    • createGauge

      public abstract <T> Gauge.GaugeBuilder<T> createGauge(String name, T obj, ToDoubleFunction<T> supplier)
      Starts building a gauge by returning a gauge builder.
      Type Parameters:
      T - the type of object
      Parameters:
      name - the name of the gauge
      obj - the object providing the value
      supplier - a value supplier turning obj into a gauge value
      Returns:
      the gauge builder
    • createGauge

      public abstract Gauge.GaugeBuilder<Supplier<Number>> createGauge(String name, Supplier<Number> supplier)
      A convenience method for building a gauge from a supplying function, holding a strong reference to this function.
      Parameters:
      name - the gauge's name
      supplier - a function that yields a double value for the gauge
      Returns:
      the gauge builder
    • createFilterDenyNameStartsWith

      public abstract MeterFilter createFilterDenyNameStartsWith(String prefix)
      Creates a filter for meters that start with the provided name prefix should NOT be present in published metrics.
      Parameters:
      prefix - when a meter name starts with the prefix, guarantee its exclusion in published metrics
      Returns:
      a filter that guarantees the exclusion of matching meters
    • createFilterAcceptNameStartsWith

      public abstract MeterFilter createFilterAcceptNameStartsWith(String prefix)
      Creates a filter for meters that start with the provided name should be present in published metrics.
      Parameters:
      prefix - When a meter name starts with the prefix, guarantee its inclusion in published metrics
      Returns:
      a filter that guarantees the inclusion of matching meters
    • createFilterDeny

      public abstract MeterFilter createFilterDeny()
      Creates a filter excluding all meter in published metrics.
      Returns:
      A filter that guarantees the exclusion of all meters.
    • createTag

      public abstract Tag createTag(String key, String value)
      Creates a tag.
      Parameters:
      key - the key
      value - the value
      Returns:
      the tag
    • createImmutableTag

      public abstract Tag createImmutableTag(String key, String value)
      Creates an immutable tag.
      Parameters:
      key - the key
      value - the value
      Returns:
      the tag
    • createId

      public abstract Meter.Id createId(String name, List<Tag> tags, String baseUnit, String description, Meter.Type type)
      Creates an id.
      Parameters:
      name - the name
      tags - the optional tags, may be null
      baseUnit - the optional base unit, may be null
      description - an optional description, may be null
      type - an optional metrics type, may be null
      Returns:
      the created id
    • createTimerStart

      public Timer.Sample createTimerStart()
      Creates a timer start sample.
      Returns:
      the timer sample
    • getSystemClock

      public abstract Clock getSystemClock()
      Returns the system clock (representation).
      Returns:
      the system clock
    • createMeasurement

      public abstract Measurement createMeasurement(Supplier<Double> valueFunction, Statistic statistic)
      Creates a measurement.
      Parameters:
      valueFunction - the (dynamic/static) value function
      statistic - the statistic type
      Returns:
      the measurement
    • buildCounter

      public static Counter.CounterBuilder buildCounter(String name)
      Starts building a counter by returning a counter builder.
      Parameters:
      name - the name of the counter
      Returns:
      the counter builder
    • buildTimer

      public static Timer.TimerBuilder buildTimer(String name)
      Starts building a timer by returning a timer builder.
      Parameters:
      name - the name of the timer
      Returns:
      the timer builder
    • buildGauge

      public static <T> Gauge.GaugeBuilder<T> buildGauge(String name, T obj, ToDoubleFunction<T> supplier)
      Starts building a gauge by returning a gauge builder.
      Type Parameters:
      T - the type of object
      Parameters:
      name - the name of the gauge
      obj - the object providing the value
      supplier - a value supplier turning obj into a gauge value
      Returns:
      the gauge builder
    • buildGauge

      public static Gauge.GaugeBuilder<Supplier<Number>> buildGauge(String name, Supplier<Number> supplier)
      Starts building a gauge by returning a gauge builder.
      Parameters:
      name - the name of the gauge
      supplier - a value supplier turning obj into a gauge value
      Returns:
      the gauge builder
    • denyNameStartsWith

      public static MeterFilter denyNameStartsWith(String prefix)
      Creates a filter for meters that start with the provided name prefix should NOT be present in published metrics.
      Parameters:
      prefix - when a meter name starts with the prefix, guarantee its exclusion in published metrics
      Returns:
      a filter that guarantees the exclusion of matching meters
    • acceptNameStartsWith

      public static MeterFilter acceptNameStartsWith(String prefix)
      Creates a filter for meters that start with the provided name should be present in published metrics.
      Parameters:
      prefix - When a meter name starts with the prefix, guarantee its inclusion in published metrics
      Returns:
      a filter that guarantees the inclusion of matching meters
    • deny

      public static MeterFilter deny()
      Creates a filter excluding all meter in published metrics.
      Returns:
      A filter that guarantees the exclusion of all meters.
    • buildTag

      public static Tag buildTag(String key, String value)
      Creates a tag.
      Parameters:
      key - the key
      value - the value
      Returns:
      the tag
    • buildImmutableTag

      public static Tag buildImmutableTag(String key, String value)
      Creates an immutable tag.
      Parameters:
      key - the key
      value - the value
      Returns:
      the tag
    • buildId

      public static Meter.Id buildId(String name, List<Tag> tags, String baseUnit, String description, Meter.Type type)
      Creates an id.
      Parameters:
      name - the name
      tags - the optional tags, may be null
      baseUnit - the optional base unit, may be null
      description - an optional description, may be null
      type - an optional metrics type, may be null
      Returns:
      the created id
    • buildMeasurement

      public static Measurement buildMeasurement(Supplier<Double> valueFunction, Statistic statistic)
      Creates a measurement.
      Parameters:
      valueFunction - the (dynamic/static) value function
      statistic - the statistic type
      Returns:
      the measurement