Class MetricsFactory
java.lang.Object
de.iip_ecosphere.platform.support.metrics.MetricsFactory
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MeterFilteracceptNameStartsWith(String prefix) Creates a filter for meters that start with the provided name should be present in published metrics.static Counter.CounterBuilderbuildCounter(String name) Starts building a counter by returning a counter builder.static Gauge.GaugeBuilder<Supplier<Number>> buildGauge(String name, Supplier<Number> supplier) Starts building a gauge by returning a gauge builder.static <T> Gauge.GaugeBuilder<T> buildGauge(String name, T obj, ToDoubleFunction<T> supplier) Starts building a gauge by returning a gauge builder.static Meter.IdCreates an id.static TagbuildImmutableTag(String key, String value) Creates an immutable tag.static MeasurementbuildMeasurement(Supplier<Double> valueFunction, Statistic statistic) Creates a measurement.static TagCreates a tag.static Timer.TimerBuilderbuildTimer(String name) Starts building a timer by returning a timer builder.abstract Counter.CounterBuildercreateCounter(String name) Starts building a counter by returning a counter builder.abstract MeterFilterCreates a filter for meters that start with the provided name should be present in published metrics.abstract MeterFilterCreates a filter excluding all meter in published metrics.abstract MeterFiltercreateFilterDenyNameStartsWith(String prefix) Creates a filter for meters that start with the provided name prefix should NOT be present in published metrics.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.abstract <T> Gauge.GaugeBuilder<T> createGauge(String name, T obj, ToDoubleFunction<T> supplier) Starts building a gauge by returning a gauge builder.abstract Meter.IdCreates an id.abstract TagcreateImmutableTag(String key, String value) Creates an immutable tag.abstract MeasurementcreateMeasurement(Supplier<Double> valueFunction, Statistic statistic) Creates a measurement.Creates a default meter registry.createRegistry(Object registry) Creates a meter registry.protected abstract MeterRegistrycreateRegistry(Object registry, boolean warn) Creates a meter registry.abstract TagCreates a tag.abstract Timer.TimerBuildercreateTimer(String name) Starts building a timer by returning a timer builder.Creates a timer start sample.static MeterFilterdeny()Creates a filter excluding all meter in published metrics.static MeterFilterdenyNameStartsWith(String prefix) Creates a filter for meters that start with the provided name prefix should NOT be present in published metrics.static MetricsFactoryReturns the Rest instance.abstract ClockReturns the system clock (representation).static voidsetInstance(MetricsFactory rest) Manually sets the instance.
-
Field Details
-
instance
-
-
Constructor Details
-
MetricsFactory
public MetricsFactory()
-
-
Method Details
-
getInstance
Returns the Rest instance.- Returns:
- the instance
-
setInstance
Manually sets the instance. Shall not be needed, but may be required in some tests.- Parameters:
rest- the Rest instance
-
createRegistry
Creates a default meter registry.- Returns:
- the registry
-
createRegistry
Creates a meter registry. This method is a bit tricky as it implies a border crossing between abstraction and implementation. The actual type ofregistrymay 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
Creates a meter registry. This method is a bit tricky as it implies a border crossing between abstraction and implementation. The actual type ofregistrymay 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 nullwarn- warn if the provided type does not match the implementation and a default is created instead- Returns:
- the registry
-
createCounter
Starts building a counter by returning a counter builder.- Parameters:
name- the name of the counter- Returns:
- the counter builder
-
createTimer
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 gaugeobj- the object providing the valuesupplier- a value supplier turningobjinto 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 namesupplier- a function that yields a double value for the gauge- Returns:
- the gauge builder
-
createFilterDenyNameStartsWith
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
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
Creates a filter excluding all meter in published metrics.- Returns:
- A filter that guarantees the exclusion of all meters.
-
createTag
Creates a tag.- Parameters:
key- the keyvalue- the value- Returns:
- the tag
-
createImmutableTag
Creates an immutable tag.- Parameters:
key- the keyvalue- 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 nametags- the optional tags, may be nullbaseUnit- the optional base unit, may be nulldescription- an optional description, may be nulltype- an optional metrics type, may be null- Returns:
- the created id
-
createTimerStart
Creates a timer start sample.- Returns:
- the timer sample
-
getSystemClock
Returns the system clock (representation).- Returns:
- the system clock
-
createMeasurement
Creates a measurement.- Parameters:
valueFunction- the (dynamic/static) value functionstatistic- the statistic type- Returns:
- the measurement
-
buildCounter
Starts building a counter by returning a counter builder.- Parameters:
name- the name of the counter- Returns:
- the counter builder
-
buildTimer
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 gaugeobj- the object providing the valuesupplier- a value supplier turningobjinto 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 gaugesupplier- a value supplier turningobjinto a gauge value- Returns:
- the gauge builder
-
denyNameStartsWith
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
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
Creates a filter excluding all meter in published metrics.- Returns:
- A filter that guarantees the exclusion of all meters.
-
buildTag
Creates a tag.- Parameters:
key- the keyvalue- the value- Returns:
- the tag
-
buildImmutableTag
Creates an immutable tag.- Parameters:
key- the keyvalue- 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 nametags- the optional tags, may be nullbaseUnit- the optional base unit, may be nulldescription- an optional description, may be nulltype- an optional metrics type, may be null- Returns:
- the created id
-
buildMeasurement
Creates a measurement.- Parameters:
valueFunction- the (dynamic/static) value functionstatistic- the statistic type- Returns:
- the measurement
-