public interface MetricsRegistry
A MetricsRegistry can contain many Probe
instances. A probe is
registered under a name, and can be read by creating a Gauge
, see
newLongGauge(String)
.
The name has this form:
[tag1=foo,tag2=bar,...]Special characters in values must be escaped, use
MetricTagger
to
register metrics with properly escaped values.
The metrics registry doesn't interpret the name in any way, it is treated as
is. For example, [tag1=foo,tag2=bar]
and [tag2=bar,tag1=foo]
will be treated as two different metrics even though they have same tags and
values. Clients making use of the metrics can use the tags. For backwards
compatibility, the name does not have to be enclosed in []
.
DynamicMetricsProvider
interface. Typical examples for the
dynamic metrics are the metrics exposed by the distributed data structures
that can be created and destroyed dynamically.
The MetricsRegistry doesn't cache the dynamic metrics, therefore the dynamic
metrics don't increase the heap live set. In exchange, they may allocate
during the collection cycle. It is therefore the responsibility of the
dynamic metric sources to keep allocation low.Modifier and Type | Method and Description |
---|---|
void |
collect(MetricsCollector collector)
Collects the content of the MetricsRegistry.
|
void |
deregisterDynamicMetricsProvider(DynamicMetricsProvider metricsProvider)
Deregisters the given dynamic metrics provider.
|
Set<String> |
getNames()
Gets a set of all current probe names.
|
ProbeLevel |
minimumLevel()
Returns the minimum ProbeLevel this MetricsRegistry is recording.
|
DoubleGauge |
newDoubleGauge(String name)
Creates a
DoubleGauge for a given metric name. |
LongGauge |
newLongGauge(String name)
Creates a
LongGauge for a given metric name. |
MetricTagger |
newMetricTagger()
Creates a new
MetricTagger . |
MetricTagger |
newMetricTagger(String namePrefix)
Creates a new
MetricTagger with the given metric name prefix. |
void |
provideMetrics(Object... providers)
For each object that implements
StaticMetricsProvider the
StaticMetricsProvider.provideStaticMetrics(MetricsRegistry) is called. |
void |
registerDynamicMetricsProvider(DynamicMetricsProvider metricsProvider)
Registers dynamic metrics sources that collect metrics in each metrics
collection cycle.
|
<S> void |
registerStaticMetrics(S source,
String namePrefix)
Scans the source object for any fields/methods that have been annotated
with
Probe annotation, and registers these fields/methods as
static probe instances. |
<S> void |
registerStaticProbe(S source,
String name,
ProbeLevel level,
DoubleProbeFunction<S> probe)
Registers a probe.
|
<S> void |
registerStaticProbe(S source,
String name,
ProbeLevel level,
LongProbeFunction<S> probe)
Registers a probe.
|
ScheduledFuture<?> |
scheduleAtFixedRate(Runnable publisher,
long period,
TimeUnit timeUnit,
ProbeLevel probeLevel)
Schedules a publisher to be executed at a fixed rate.
|
ProbeLevel minimumLevel()
LongGauge newLongGauge(String name)
LongGauge
for a given metric name.
If no gauge exists for the name, it will be created but no probe is set.
The reason to do so is that you don't want to depend on the order of
registration. Perhaps you want to read out e.g. operations.count gauge,
but the OperationService has not started yet and the metric is not yet
available. Another cause is that perhaps a probe is not registered, but
the metric is created. For example when experimenting with a new
implementation, e.g. a new OperationService implementation, that doesn't
provide the operation.count probe.
Multiple calls with the same name return different Gauge instances; so
the Gauge instance is not cached. This is done to prevent memory leaks.name
- the name of the metric.NullPointerException
- if name is null.DoubleGauge newDoubleGauge(String name)
DoubleGauge
for a given metric name.name
- name of the metricNullPointerException
- if name is null.newLongGauge(String)
Set<String> getNames()
<S> void registerStaticMetrics(S source, String namePrefix)
Probe
annotation, and registers these fields/methods as
static probe instances.
If a probe is called 'queueSize' and the namePrefix is 'operations', then the name of the probe instance is 'operations.queueSize'.
If a probe with the same name already exists, then the probe is replaced.
If an object has no @Probe annotations, the call is ignored.
source
- the object to scan.namePrefix
- the name prefix.NullPointerException
- if namePrefix or source is null.IllegalArgumentException
- if the source contains a Probe
annotation on a field/method of unsupported type.void registerDynamicMetricsProvider(DynamicMetricsProvider metricsProvider)
metricsProvider
- The object that provides dynamic metricsvoid deregisterDynamicMetricsProvider(DynamicMetricsProvider metricsProvider)
metricsProvider
- The metrics provider to deregister<S> void registerStaticProbe(S source, String name, ProbeLevel level, LongProbeFunction<S> probe)
name
- the name of the probe.level
- the ProbeLevelprobe
- the probeNullPointerException
- if source, name, level or probe is null.<S> void registerStaticProbe(S source, String name, ProbeLevel level, DoubleProbeFunction<S> probe)
name
- the name of the probelevel
- the ProbeLevelprobe
- the probeNullPointerException
- if source, name, level or probe is null.ScheduledFuture<?> scheduleAtFixedRate(Runnable publisher, long period, TimeUnit timeUnit, ProbeLevel probeLevel)
publisher
- the published task that needs to be executedperiod
- the time between executionstimeUnit
- the time unit for periodprobeLevel
- the ProbeLevel publisher it publishing on. This is needed to prevent scheduling
publishers if their probe level isn't sufficient.NullPointerException
- if publisher or timeUnit is null.void collect(MetricsCollector collector)
collector
- the collector that consumes the metrics collectedNullPointerException
- if collector is null.void provideMetrics(Object... providers)
StaticMetricsProvider
the
StaticMetricsProvider.provideStaticMetrics(MetricsRegistry)
is called.providers
- the array of objects to initialize.MetricTagger newMetricTagger()
MetricTagger
.MetricTagger newMetricTagger(String namePrefix)
MetricTagger
with the given metric name prefix.
This prefix will be appended to "metric" tag names for all metrics
created with the MetricTagger.namePrefix
- the name prefix.Copyright © 2019 Hazelcast, Inc.. All rights reserved.