Class MeterRegistryHolder
- java.lang.Object
-
- org.opends.server.api.MeterRegistryHolder
-
- All Implemented Interfaces:
MeterRegistry
public final class MeterRegistryHolder extends Object implements MeterRegistry
Decorator for a meter registry. It can:- prefix the dimensional meter names for added meters
- prefix the hierarchical meter names for added meters (via the
hierarchicalNamePrefix(String)
method) - add additional tags for added meters
- forward the meter creation to the decorated
MeterRegistry
- compute the LDAP attribute names and types and keep them for later retrieval
Tags and attribute types
For adding tags, a simple rule of thumb is to add component names as tags.
Generally, tag pairs (keys + values) are also used in the
Dn
of the monitor provider. Most of theRdn
s will typically usecn
attribute type, but for some of them you might want to use another attribute type. A simple rule of thumb is: whatever used as tag could have its own attribute type.Use of factory methods
The various
*Gauge
factory methods help create gauges in the underlying MeterRegistry.The
monitoringGauge(String, Supplier)
method may be used to only output a metric tocn=monitor
and derived monitoring systems (and NOT to the following endpoints: prometheus, graphite, crest metrics, etc.).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.forgerock.monitoring.api.instrument.MeterRegistry
MeterRegistry.Config, MeterRegistry.More
-
-
Field Summary
Fields Modifier and Type Field Description static String
TAG_ATTRIBUTE_NAME
The tag to use to map the ldap name.
-
Constructor Summary
Constructors Constructor Description MeterRegistryHolder(String dimensionalNamePrefix, MeterRegistry registry)
Constructor for this class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
booleanGauge(String name, String ldapAttributeName, Supplier<Boolean> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theBoolean
to a double.void
booleanGauge(String name, Supplier<Boolean> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theBoolean
to a double.MeterRegistry.Config
config()
Counter
counter(String name)
Tracks a monotonically increasing value.Counter
counter(Meter.Id id)
Only used byCounter.builder(String)
.void
dateTimeGauge(String name, String ldapAttributeName, Supplier<GeneralizedTime> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theGeneralizedTime
to a double by using theGeneralizedTime.getTimeInMillis()
function.void
dateTimeGauge(String name, Supplier<GeneralizedTime> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theGeneralizedTime
to a double by using theGeneralizedTime.getTimeInMillis()
function.void
deregisterAll()
Deregisters all the meters registered through this registry.void
deregisterMatching(MeterFilter filter)
Deregister meters matching the provided filter.void
doubleGauge(String name, DoubleSupplier valueFunction)
Convenience method that creates a gauge returning a double that will be added to the parent meter registry.void
durationGauge(String name, Supplier<Duration> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theDuration
using theDuration.toMillis()
method.Gauge
gauge(String name, Number number)
Register a gauge that reports the value of theNumber
.<T> Gauge
gauge(Meter.Id id, T obj, ToDoubleFunction<T> valueFunction)
Only used byGauge.builder(String, Object, ToDoubleFunction)
.static String
getAttributeName(String meterName)
Returns the LDAP attribute name corresponding to this meter name.Map<String,Meter>
getLdapMeters()
Returns a Map from ldap attribute names to the corresponding meters.List<Meter>
getMeters()
MeterRegistryHolder
hierarchicalNamePrefix(String hierarchicalNamePrefix)
Sets the prefix for the hierarchical metric names.<V> void
monitoringGauge(String name, Supplier<V> valueFunction)
Creates an object gauge that is never added to the parent meter registry (it only appears in ldap meters).MeterRegistry.More
more()
Access to less frequently used meter types and patterns.<V extends Number>
voidnumberGauge(String name, Supplier<V> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theNumber
to a double by using theNumber.doubleValue()
function.Meter
register(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements)
Register a custom meter type.<T extends Enum<T>>
voidstateSet(String name, Supplier<T> stateSupplier)
Creates both a metric, containing the actual state value, that is never added to the parent meter registry (it only appears in ldap meters), and a gauge for each state that will be added to the parent meter registry.DistributionSummary
summary(String name)
Measures the distribution of samples.DistributionSummary
summary(Meter.Id id, HistogramConfig histogramConfig)
Only used byDistributionSummary.builder(String)
.MeterRegistryHolder
tag(String key, String value)
Adds a tag that will be automatically added to all meters registered against this meter registry.Timer
timer(String name)
Measures the time taken for short tasks and the count of these tasks.Timer
timer(Meter.Id id, HistogramConfig histogramConfig, PauseDetector pauseDetectorOverride)
Only used byTimer.builder(String)
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.forgerock.monitoring.api.instrument.MeterRegistry
find, forEachMeter, get
-
-
-
-
Field Detail
-
TAG_ATTRIBUTE_NAME
public static final String TAG_ATTRIBUTE_NAME
The tag to use to map the ldap name.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MeterRegistryHolder
public MeterRegistryHolder(String dimensionalNamePrefix, MeterRegistry registry)
Constructor for this class.- Parameters:
dimensionalNamePrefix
- prefix for the dimensional metric names. It will be used as a prefix for the hierarchical metric names, unless a different one is set usinghierarchicalNamePrefix(String)
.registry
- the decorated registry
-
-
Method Detail
-
hierarchicalNamePrefix
public MeterRegistryHolder hierarchicalNamePrefix(String hierarchicalNamePrefix)
Sets the prefix for the hierarchical metric names.- Parameters:
hierarchicalNamePrefix
- the hierarchical name prefix to use- Returns:
- this object
-
tag
public MeterRegistryHolder tag(String key, String value)
Adds a tag that will be automatically added to all meters registered against this meter registry.- Parameters:
key
- the tag's keyvalue
- the tag's value- Returns:
- this meter registry
-
counter
public Counter counter(Meter.Id id)
Description copied from interface:MeterRegistry
Only used byCounter.builder(String)
.- Specified by:
counter
in interfaceMeterRegistry
- Parameters:
id
- The identifier for this counter.- Returns:
- A new or existing counter.
-
getAttributeName
public static String getAttributeName(String meterName)
Returns the LDAP attribute name corresponding to this meter name. This method prefixes the providedmeterName
with ds-mon-.- Parameters:
meterName
- the meter name to prefix- Returns:
- the LDAP attribute name corresponding to this meter name.
-
booleanGauge
public void booleanGauge(String name, Supplier<Boolean> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theBoolean
to a double.- true is converted to 1
- false is converted to 0
- Parameters:
name
- the metric namevalueFunction
- a function which returns any object which will be converted to String
-
booleanGauge
public void booleanGauge(String name, String ldapAttributeName, Supplier<Boolean> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theBoolean
to a double.- true is converted to 1
- false is converted to 0
- Parameters:
name
- the metric nameldapAttributeName
- the LDAP attribute namevalueFunction
- a function which returns any object which will be converted to String
-
dateTimeGauge
public void dateTimeGauge(String name, Supplier<GeneralizedTime> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theGeneralizedTime
to a double by using theGeneralizedTime.getTimeInMillis()
function.- Parameters:
name
- the metric namevalueFunction
- a function which returns aGeneralizedTime
object that will be converted to String
-
dateTimeGauge
public void dateTimeGauge(String name, String ldapAttributeName, Supplier<GeneralizedTime> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theGeneralizedTime
to a double by using theGeneralizedTime.getTimeInMillis()
function.- Parameters:
name
- the metric nameldapAttributeName
- the LDAP attribute namevalueFunction
- a function which returns aGeneralizedTime
object that will be converted to String
-
durationGauge
public void durationGauge(String name, Supplier<Duration> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theDuration
using theDuration.toMillis()
method.- Parameters:
name
- the metric namevalueFunction
- a function which returns aDuration
object that will be converted to String
-
doubleGauge
public void doubleGauge(String name, DoubleSupplier valueFunction)
Convenience method that creates a gauge returning a double that will be added to the parent meter registry.- Parameters:
name
- the metric namevalueFunction
- a function which returns any object which will be converted to String
-
numberGauge
public <V extends Number> void numberGauge(String name, Supplier<V> valueFunction)
Creates both an object gauge that is never added to the parent meter registry (it only appears in ldap meters), and a gauge returning a double that will be added to the parent meter registry converting theNumber
to a double by using theNumber.doubleValue()
function.- Type Parameters:
V
- type of the value returned by thevalueFunction
provided- Parameters:
name
- the metric namevalueFunction
- a function which returns any object which will be converted to String
-
stateSet
public <T extends Enum<T>> void stateSet(String name, Supplier<T> stateSupplier)
Creates both a metric, containing the actual state value, that is never added to the parent meter registry (it only appears in ldap meters), and a gauge for each state that will be added to the parent meter registry. The gauges return 1 when the evaluated state is the actual one and return 0 otherwise.- Type Parameters:
T
- the enum listing the possible states- Parameters:
name
- the metric name, also used as a dimension holding the evaluated state's valuestateSupplier
- function returning the actual state
-
monitoringGauge
public <V> void monitoringGauge(String name, Supplier<V> valueFunction)
Creates an object gauge that is never added to the parent meter registry (it only appears in ldap meters).In particular, this method may be used to only output a metric to
cn=monitor
and derived monitoring systems (rather than the following endpoints: prometheus, graphite, crest metrics, etc.).- Type Parameters:
V
- type of the value returned by thevalueFunction
provided- Parameters:
name
- the metric namevalueFunction
- a function which returns any object which will be converted to String
-
gauge
public <T> Gauge gauge(Meter.Id id, T obj, ToDoubleFunction<T> valueFunction)
Description copied from interface:MeterRegistry
Only used byGauge.builder(String, Object, ToDoubleFunction)
.- Specified by:
gauge
in interfaceMeterRegistry
- Type Parameters:
T
- The type of the state object from which the gauge value is extracted.- Parameters:
id
- The identifier for this gauge.obj
- State object used to compute a value.valueFunction
- Function that is applied on the value for the number.- Returns:
- A new or existing long task timer.
-
gauge
public Gauge gauge(String name, Number number)
Register a gauge that reports the value of theNumber
.- Parameters:
name
- Name of the gauge being registered.number
- Thread-safe implementation ofNumber
used to access the value.- Returns:
- The number that was passed in so the registration can be done as part of an assignment statement.
-
counter
public Counter counter(String name)
Tracks a monotonically increasing value.- Parameters:
name
- The base metric name- Returns:
- A new or existing counter.
-
timer
public Timer timer(String name)
Measures the time taken for short tasks and the count of these tasks.- Parameters:
name
- The base metric name- Returns:
- A new or existing timer.
-
timer
public Timer timer(Meter.Id id, HistogramConfig histogramConfig, PauseDetector pauseDetectorOverride)
Description copied from interface:MeterRegistry
Only used byTimer.builder(String)
.- Specified by:
timer
in interfaceMeterRegistry
- Parameters:
id
- The identifier for this timer.histogramConfig
- Configuration that governs how distribution statistics are computed.- Returns:
- A new or existing timer.
-
summary
public DistributionSummary summary(String name)
Measures the distribution of samples.- Parameters:
name
- The base metric name- Returns:
- A new or existing distribution summary.
-
summary
public DistributionSummary summary(Meter.Id id, HistogramConfig histogramConfig)
Description copied from interface:MeterRegistry
Only used byDistributionSummary.builder(String)
.- Specified by:
summary
in interfaceMeterRegistry
- Parameters:
id
- The identifier for this distribution summary.histogramConfig
- Configuration that governs how distribution statistics are computed.- Returns:
- A new or existing distribution summary.
-
register
public Meter register(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements)
Description copied from interface:MeterRegistry
Register a custom meter type.- Specified by:
register
in interfaceMeterRegistry
- Parameters:
id
- Id of the meter being registered.type
- Meter type, which may be used by naming conventions to normalize the name.measurements
- A sequence of measurements describing how to sample the meter.- Returns:
- The registry.
-
deregisterMatching
public void deregisterMatching(MeterFilter filter)
Description copied from interface:MeterRegistry
Deregister meters matching the provided filter.- Specified by:
deregisterMatching
in interfaceMeterRegistry
- Parameters:
filter
- a non-null meter filter
-
config
public MeterRegistry.Config config()
- Specified by:
config
in interfaceMeterRegistry
- Returns:
- A configuration object used to change the behavior of this registry.
-
more
public MeterRegistry.More more()
Description copied from interface:MeterRegistry
Access to less frequently used meter types and patterns.- Specified by:
more
in interfaceMeterRegistry
- Returns:
- Access to additional meter types and patterns.
-
getMeters
public List<Meter> getMeters()
- Specified by:
getMeters
in interfaceMeterRegistry
- Returns:
- The set of registered meters.
-
getLdapMeters
public Map<String,Meter> getLdapMeters()
Returns a Map from ldap attribute names to the corresponding meters.- Returns:
- a Map from ldap attribute names to the corresponding meters
-
deregisterAll
public void deregisterAll()
Deregisters all the meters registered through this registry. This includes:- the meters registered against the parent registry
- the ldap meters
-
-