public interface Registry extends Iterable<Meter>
Modifier and Type | Method and Description |
---|---|
Clock |
clock()
The clock used by the registry for timing events.
|
default <T extends Collection<?>> |
collectionSize(Id id,
T collection)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default <T extends Collection<?>> |
collectionSize(String name,
T collection)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default RegistryConfig |
config()
Configuration settings used for this registry.
|
Counter |
counter(Id id)
Measures the rate of some activity.
|
default Counter |
counter(String name)
Measures the rate of some activity.
|
default Counter |
counter(String name,
Iterable<Tag> tags)
Measures the rate of some activity.
|
default Counter |
counter(String name,
String... tags)
Measures the rate of some activity.
|
default Stream<Counter> |
counters()
Returns a stream of all registered counters.
|
Id |
createId(String name)
Creates an identifier for a meter.
|
Id |
createId(String name,
Iterable<Tag> tags)
Creates an identifier for a meter.
|
default Id |
createId(String name,
Map<String,String> tags)
Creates an identifier for a meter.
|
default Id |
createId(String name,
String... tags)
Creates an identifier for a meter.
|
default Stream<DistributionSummary> |
distributionSummaries()
Returns a stream of all registered distribution summaries.
|
DistributionSummary |
distributionSummary(Id id)
Measures the rate and variation in amount for some activity.
|
default DistributionSummary |
distributionSummary(String name)
Measures the sample distribution of events.
|
default DistributionSummary |
distributionSummary(String name,
Iterable<Tag> tags)
Measures the sample distribution of events.
|
default DistributionSummary |
distributionSummary(String name,
String... tags)
Measures the sample distribution of events.
|
Gauge |
gauge(Id id)
Represents a value sampled from another source.
|
default <T extends Number> |
gauge(Id id,
T number)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default <T> T |
gauge(Id id,
T obj,
ToDoubleFunction<T> f)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default Gauge |
gauge(String name)
Represents a value sampled from another source.
|
default Gauge |
gauge(String name,
Iterable<Tag> tags)
Represents a value sampled from another source.
|
default <T extends Number> |
gauge(String name,
Iterable<Tag> tags,
T number)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default Gauge |
gauge(String name,
String... tags)
Represents a value sampled from another source.
|
default <T extends Number> |
gauge(String name,
T number)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default <T> T |
gauge(String name,
T obj,
ToDoubleFunction<T> f)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default Stream<Gauge> |
gauges()
Returns a stream of all registered gauges.
|
Meter |
get(Id id)
Returns the meter associated with a given id.
|
Iterator<Meter> |
iterator()
Iterator for traversing the set of meters in the registry.
|
default LongTaskTimer |
longTaskTimer(Id id)
Deprecated.
Use
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release. |
default LongTaskTimer |
longTaskTimer(String name)
Deprecated.
Use
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release. |
default LongTaskTimer |
longTaskTimer(String name,
Iterable<Tag> tags)
Deprecated.
Use
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release. |
default LongTaskTimer |
longTaskTimer(String name,
String... tags)
Deprecated.
Use
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release. |
default <T extends Map<?,?>> |
mapSize(Id id,
T collection)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default <T extends Map<?,?>> |
mapSize(String name,
T collection)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
Gauge |
maxGauge(Id id)
Measures the maximum value recorded since the last reset.
|
default Gauge |
maxGauge(String name)
Measures the maximum value recorded since the last reset.
|
default Gauge |
maxGauge(String name,
Iterable<Tag> tags)
Measures the maximum value recorded since the last reset.
|
default Gauge |
maxGauge(String name,
String... tags)
Measures the maximum value recorded since the last reset.
|
default Stream<Measurement> |
measurements()
Returns a stream with the current flattened set of measurements across all meters.
|
default void |
methodValue(Id id,
Object obj,
String method)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default void |
methodValue(String name,
Object obj,
String method)
Deprecated.
Use
PolledMeter instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter s will be handled
separately. This method is scheduled for removal in a future release. |
default void |
propagate(String msg,
Throwable t)
Log a warning and if enabled propagate the exception
t . |
default void |
propagate(Throwable t)
Log a warning using the message from the exception and if enabled propagate the
exception
t . |
void |
register(Meter meter)
Deprecated.
Code outside of Spectator should not implement the Meter interface. This
method is scheduled for removal in a future release.
|
ConcurrentMap<Id,Object> |
state()
Returns a map that can be used to associate state with the registry.
|
default Stream<Meter> |
stream()
Returns a stream of all registered meters.
|
Timer |
timer(Id id)
Measures the rate and time taken for short running tasks.
|
default Timer |
timer(String name)
Measures the time taken for short tasks.
|
default Timer |
timer(String name,
Iterable<Tag> tags)
Measures the time taken for short tasks.
|
default Timer |
timer(String name,
String... tags)
Measures the time taken for short tasks.
|
default Stream<Timer> |
timers()
Returns a stream of all registered timers.
|
default <T extends Registry> |
underlying(Class<T> c)
Returns the first underlying registry that is an instance of
c . |
forEach, spliterator
Clock clock()
default RegistryConfig config()
Id createId(String name)
name
- Description of the measurement that is being collected.Id createId(String name, Iterable<Tag> tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.@Deprecated void register(Meter meter)
ConcurrentMap<Id,Object> state()
LongTaskTimer
.Counter counter(Id id)
id
- Identifier created by a call to createId(java.lang.String)
DistributionSummary distributionSummary(Id id)
id
- Identifier created by a call to createId(java.lang.String)
Timer timer(Id id)
id
- Identifier created by a call to createId(java.lang.String)
Gauge gauge(Id id)
Gauge.set(double)
.
Registry implementations are free to expire the gauge if it has not been updated in the
last minute. If you do not want to worry about the sampling, then use PolledMeter
instead.id
- Identifier created by a call to createId(java.lang.String)
Gauge maxGauge(Id id)
distributionSummary(Id)
which provides a max along with other stats for most
registry implementations.id
- Identifier created by a call to createId(java.lang.String)
Meter get(Id id)
id
- Identifier for the meter.default <T extends Registry> T underlying(Class<T> c)
c
.default Id createId(String name, String... tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Id createId(String name, Map<String,String> tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Counter counter(String name)
name
- Description of the measurement that is being collected.default Counter counter(String name, Iterable<Tag> tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Counter counter(String name, String... tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default DistributionSummary distributionSummary(String name)
name
- Description of the measurement that is being collected.default DistributionSummary distributionSummary(String name, Iterable<Tag> tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default DistributionSummary distributionSummary(String name, String... tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Timer timer(String name)
name
- Description of the measurement that is being collected.default Timer timer(String name, Iterable<Tag> tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Timer timer(String name, String... tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Gauge gauge(String name)
name
- Description of the measurement that is being collected.default Gauge gauge(String name, Iterable<Tag> tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Gauge gauge(String name, String... tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Gauge maxGauge(String name)
name
- Description of the measurement that is being collected.default Gauge maxGauge(String name, Iterable<Tag> tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.default Gauge maxGauge(String name, String... tags)
name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.@Deprecated default LongTaskTimer longTaskTimer(Id id)
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release.id
- Identifier for the metric being registered.@Deprecated default LongTaskTimer longTaskTimer(String name)
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release.name
- Description of the measurement that is being collected.@Deprecated default LongTaskTimer longTaskTimer(String name, Iterable<Tag> tags)
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release.name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.@Deprecated default LongTaskTimer longTaskTimer(String name, String... tags)
LongTaskTimer.get(Registry, Id)
instead. This method is scheduled for removal in a future release.name
- Description of the measurement that is being collected.tags
- Other dimensions that can be used to classify the measurement.@Deprecated default <T extends Number> T gauge(Id id, T number)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.Number
and report
it as a gauge.id
- Identifier for the metric being registered.number
- Thread-safe implementation of Number
used to access the value.@Deprecated default <T extends Number> T gauge(String name, T number)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.Number
and report
it as a gauge. See PolledMeter.Builder#monitorValue(Number)
for more information.name
- Name of the metric being registered.number
- Thread-safe implementation of Number
used to access the value.@Deprecated default <T extends Number> T gauge(String name, Iterable<Tag> tags, T number)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.Number
and report
it as a gauge. See gauge(Id, Number)
for more information.name
- Name of the metric being registered.tags
- Sequence of dimensions for breaking down the name.number
- Thread-safe implementation of Number
used to access the value.@Deprecated default <T> T gauge(Id id, T obj, ToDoubleFunction<T> f)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.gauge(Id, Object, ToDoubleFunction)
for more information.id
- Identifier for the metric being registered.obj
- Object used to compute a value.f
- Function that is applied on the value for the number.@Deprecated default <T> T gauge(String name, T obj, ToDoubleFunction<T> f)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.gauge(Id, Object, ToDoubleFunction)
for more information.name
- Name of the metric being registered.obj
- Object used to compute a value.f
- Function that is applied on the value for the number.@Deprecated default <T extends Collection<?>> T collectionSize(Id id, T collection)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.Collection.size()
can be expensive for some collection
implementations and should be considered before registering.
For more information see gauge(Id, Object, ToDoubleFunction)
.id
- Identifier for the metric being registered.collection
- Thread-safe implementation of Collection
used to access the value.@Deprecated default <T extends Collection<?>> T collectionSize(String name, T collection)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.collectionSize(Id, Collection)
for more information.name
- Name of the metric being registered.collection
- Thread-safe implementation of Collection
used to access the value.@Deprecated default <T extends Map<?,?>> T mapSize(Id id, T collection)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.Map.size()
can be expensive for some map
implementations and should be considered before registering.
For more information see gauge(Id, Object, ToDoubleFunction)
.id
- Identifier for the metric being registered.collection
- Thread-safe implementation of Map
used to access the value.@Deprecated default <T extends Map<?,?>> T mapSize(String name, T collection)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.mapSize(Id, Map)
for more information.name
- Name of the metric being registered.collection
- Thread-safe implementation of Map
used to access the value.@Deprecated default void methodValue(Id id, Object obj, String method)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.gauge(Id, Object, ToDoubleFunction)
should be preferred. Use this technique only if there access or other restrictions prevent
using a proper function reference. However, keep in mind that makes your code more brittle
and prone to failure in the future.
For more information see gauge(Id, Object, ToDoubleFunction)
.id
- Identifier for the metric being registered.obj
- Object used to compute a value.method
- Name of the method to invoke on the object.@Deprecated default void methodValue(String name, Object obj, String method)
PolledMeter
instead. This method has been deprecated to help
reduce confusion between active gauges that are explicitly updated by the
user and passive gauges that are polled in the background. Going forward
the registry methods will only be used for the core types directly updated
by the user. Other patterns such as PolledMeter
s will be handled
separately. This method is scheduled for removal in a future release.methodValue(Id, Object, String)
for more information.name
- Name of the metric being registered.obj
- Object used to compute a value.method
- Name of the method to invoke on the object.default Stream<Measurement> measurements()
stream()
to get the data as it will
automatically handle expired meters, NaN values, etc.default Stream<Counter> counters()
LongSummaryStatistics summary = r.counters() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(Counter::count));
default Stream<DistributionSummary> distributionSummaries()
LongSummaryStatistics countSummary = r.distributionSummaries() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(DistributionSummary::count)); LongSummaryStatistics totalSummary = r.distributionSummaries() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(DistributionSummary::totalAmount)); double avgAmount = (double) totalSummary.getSum() / countSummary.getSum();
default Stream<Timer> timers()
LongSummaryStatistics countSummary = r.timers() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(Timer::count)); LongSummaryStatistics totalSummary = r.timers() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(Timer::totalTime)); double avgTime = (double) totalSummary.getSum() / countSummary.getSum();
default Stream<Gauge> gauges()
DoubleSummaryStatistics valueSummary = r.gauges() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingDouble(Gauge::value)); double sum = (double) valueSummary.getSum();
default void propagate(String msg, Throwable t)
t
. As a general rule
instrumentation code should degrade gracefully and avoid impacting the core application. If
the user makes a mistake and causes something to break, then it should not impact the
application unless that mistake triggers a problem outside of the instrumentation code.
However, in test code it is often better to throw so that mistakes are caught and corrected.
This method is used to handle exceptions internal to the instrumentation code. Propagation
is controlled by the RegistryConfig.propagateWarnings()
setting. If the setting
is true, then the exception will be propagated. Otherwise the exception will only get logged
as a warning.msg
- Message written out to the log.t
- Exception to log and optionally propagate.default void propagate(Throwable t)
t
. For more information see propagate(String, Throwable)
.t
- Exception to log and optionally propagate.