Package org.eclipse.microprofile.metrics
Class MetricRegistry
- java.lang.Object
-
- org.eclipse.microprofile.metrics.MetricRegistry
-
public abstract class MetricRegistry extends java.lang.Object
The registry that stores metrics and their metadata. The MetricRegistry provides methods to register, create and retrieve metrics and their respective metadata.- See Also:
MetricFilter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetricRegistry.Type
An enumeration representing the scopes of the MetricRegistry
-
Constructor Summary
Constructors Constructor Description MetricRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract Counter
counter(java.lang.String name)
abstract Counter
counter(Metadata metadata)
abstract java.util.SortedMap<java.lang.String,Counter>
getCounters()
Returns a map of all the counters in the registry and their names.abstract java.util.SortedMap<java.lang.String,Counter>
getCounters(MetricFilter filter)
Returns a map of all the counters in the registry and their names which match the given filter.abstract java.util.SortedMap<java.lang.String,Gauge>
getGauges()
Returns a map of all the gauges in the registry and their names.abstract java.util.SortedMap<java.lang.String,Gauge>
getGauges(MetricFilter filter)
Returns a map of all the gauges in the registry and their names which match the given filter.abstract java.util.SortedMap<java.lang.String,Histogram>
getHistograms()
Returns a map of all the histograms in the registry and their names.abstract java.util.SortedMap<java.lang.String,Histogram>
getHistograms(MetricFilter filter)
Returns a map of all the histograms in the registry and their names which match the given filter.abstract java.util.Map<java.lang.String,Metadata>
getMetadata()
Returns a map of all the metadata in the registry and their names.abstract java.util.SortedMap<java.lang.String,Meter>
getMeters()
Returns a map of all the meters in the registry and their names.abstract java.util.SortedMap<java.lang.String,Meter>
getMeters(MetricFilter filter)
Returns a map of all the meters in the registry and their names which match the given filter.abstract java.util.Map<java.lang.String,Metric>
getMetrics()
Returns a map of all the metrics in the registry and their names.abstract java.util.SortedSet<java.lang.String>
getNames()
Returns a set of the names of all the metrics in the registry.abstract java.util.SortedMap<java.lang.String,Timer>
getTimers()
Returns a map of all the timers in the registry and their names.abstract java.util.SortedMap<java.lang.String,Timer>
getTimers(MetricFilter filter)
Returns a map of all the timers in the registry and their names which match the given filter.abstract Histogram
histogram(java.lang.String name)
abstract Histogram
histogram(Metadata metadata)
abstract Meter
meter(java.lang.String name)
abstract Meter
meter(Metadata metadata)
static java.lang.String
name(java.lang.Class<?> klass, java.lang.String... names)
Concatenates a class name and elements to form a dotted name, eliding any null values or empty strings.static java.lang.String
name(java.lang.String name, java.lang.String... names)
Concatenates elements to form a dotted name, eliding any null values or empty strings.abstract <T extends Metric>
Tregister(java.lang.String name, T metric)
Given aMetric
, registers it under the given name.abstract <T extends Metric>
Tregister(java.lang.String name, T metric, Metadata metadata)
Deprecated.As of version 1.1, useregister(Metadata, Metric)
insteadabstract <T extends Metric>
Tregister(Metadata metadata, T metric)
abstract boolean
remove(java.lang.String name)
Removes the metric with the given name.abstract void
removeMatching(MetricFilter filter)
Removes all metrics which match the given filter.abstract Timer
timer(java.lang.String name)
abstract Timer
timer(Metadata metadata)
-
-
-
Method Detail
-
name
public static java.lang.String name(java.lang.String name, java.lang.String... names)
Concatenates elements to form a dotted name, eliding any null values or empty strings.- Parameters:
name
- the first element of the namenames
- the remaining elements of the name- Returns:
name
andnames
concatenated by periods
-
name
public static java.lang.String name(java.lang.Class<?> klass, java.lang.String... names)
Concatenates a class name and elements to form a dotted name, eliding any null values or empty strings.- Parameters:
klass
- the first element of the namenames
- the remaining elements of the name- Returns:
klass
andnames
concatenated by periods
-
register
public abstract <T extends Metric> T register(java.lang.String name, T metric) throws java.lang.IllegalArgumentException
Given aMetric
, registers it under the given name. AMetadata
object will be registered with the name and type.- Type Parameters:
T
- the type of the metric- Parameters:
name
- the name of the metricmetric
- the metric- Returns:
metric
- Throws:
java.lang.IllegalArgumentException
- if the name is already registered
-
register
@Deprecated public abstract <T extends Metric> T register(java.lang.String name, T metric, Metadata metadata) throws java.lang.IllegalArgumentException
Deprecated. As of version 1.1, useregister(Metadata, Metric)
instead- Type Parameters:
T
- the type of the metric- Parameters:
name
- the name of the metricmetric
- the metricmetadata
- the metadata- Returns:
metric
- Throws:
java.lang.IllegalArgumentException
- if the name is already registered
-
register
public abstract <T extends Metric> T register(Metadata metadata, T metric) throws java.lang.IllegalArgumentException
- Type Parameters:
T
- the type of the metric- Parameters:
metadata
- the metadatametric
- the metric- Returns:
metric
- Throws:
java.lang.IllegalArgumentException
- if the name is already registered- Since:
- 1.1
-
counter
public abstract Counter counter(java.lang.String name)
Return theCounter
registered under this name; or create and register a newCounter
if none is registered. If aCounter
was created, aMetadata
object will be registered with the name and type.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Counter
-
counter
public abstract Counter counter(Metadata metadata)
Return theCounter
registered under theMetadata
's name; or create and register a newCounter
if none is registered. If aCounter
was created, the providedMetadata
object will be registered.Note: The
Metadata
will not be updated if the metric is already registered.- Parameters:
metadata
- the name of the metric- Returns:
- a new or pre-existing
Counter
-
histogram
public abstract Histogram histogram(java.lang.String name)
Return theHistogram
registered under this name; or create and register a newHistogram
if none is registered. If aHistogram
was created, aMetadata
object will be registered with the name and type.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Histogram
-
histogram
public abstract Histogram histogram(Metadata metadata)
Return theHistogram
registered under theMetadata
's name; or create and register a newHistogram
if none is registered. If aHistogram
was created, the providedMetadata
object will be registered.Note: The
Metadata
will not be updated if the metric is already registered.- Parameters:
metadata
- the name of the metric- Returns:
- a new or pre-existing
Histogram
-
meter
public abstract Meter meter(java.lang.String name)
Return theMeter
registered under this name; or create and register a newMeter
if none is registered. If aMeter
was created, aMetadata
object will be registered with the name and type.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Meter
-
meter
public abstract Meter meter(Metadata metadata)
Return theMeter
registered under theMetadata
's name; or create and register a newMeter
if none is registered. If aMeter
was created, the providedMetadata
object will be registered.Note: The
Metadata
will not be updated if the metric is already registered.- Parameters:
metadata
- the name of the metric- Returns:
- a new or pre-existing
Meter
-
timer
public abstract Timer timer(java.lang.String name)
Return theTimer
registered under this name; or create and register a newTimer
if none is registered. If aTimer
was created, aMetadata
object will be registered with the name and type.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Timer
-
timer
public abstract Timer timer(Metadata metadata)
Return theTimer
registered under theMetadata
's name; or create and register a newTimer
if none is registered. If aTimer
was created, the providedMetadata
object will be registered.Note: The
Metadata
will not be updated if the metric is already registered.- Parameters:
metadata
- the name of the metric- Returns:
- a new or pre-existing
Timer
-
remove
public abstract boolean remove(java.lang.String name)
Removes the metric with the given name.- Parameters:
name
- the name of the metric- Returns:
- whether or not the metric was removed
-
removeMatching
public abstract void removeMatching(MetricFilter filter)
Removes all metrics which match the given filter.- Parameters:
filter
- a filter
-
getNames
public abstract java.util.SortedSet<java.lang.String> getNames()
Returns a set of the names of all the metrics in the registry.- Returns:
- the names of all the metrics
-
getGauges
public abstract java.util.SortedMap<java.lang.String,Gauge> getGauges()
Returns a map of all the gauges in the registry and their names.- Returns:
- all the gauges in the registry
-
getGauges
public abstract java.util.SortedMap<java.lang.String,Gauge> getGauges(MetricFilter filter)
Returns a map of all the gauges in the registry and their names which match the given filter.- Parameters:
filter
- the metric filter to match- Returns:
- all the gauges in the registry
-
getCounters
public abstract java.util.SortedMap<java.lang.String,Counter> getCounters()
Returns a map of all the counters in the registry and their names.- Returns:
- all the counters in the registry
-
getCounters
public abstract java.util.SortedMap<java.lang.String,Counter> getCounters(MetricFilter filter)
Returns a map of all the counters in the registry and their names which match the given filter.- Parameters:
filter
- the metric filter to match- Returns:
- all the counters in the registry
-
getHistograms
public abstract java.util.SortedMap<java.lang.String,Histogram> getHistograms()
Returns a map of all the histograms in the registry and their names.- Returns:
- all the histograms in the registry
-
getHistograms
public abstract java.util.SortedMap<java.lang.String,Histogram> getHistograms(MetricFilter filter)
Returns a map of all the histograms in the registry and their names which match the given filter.- Parameters:
filter
- the metric filter to match- Returns:
- all the histograms in the registry
-
getMeters
public abstract java.util.SortedMap<java.lang.String,Meter> getMeters()
Returns a map of all the meters in the registry and their names.- Returns:
- all the meters in the registry
-
getMeters
public abstract java.util.SortedMap<java.lang.String,Meter> getMeters(MetricFilter filter)
Returns a map of all the meters in the registry and their names which match the given filter.- Parameters:
filter
- the metric filter to match- Returns:
- all the meters in the registry
-
getTimers
public abstract java.util.SortedMap<java.lang.String,Timer> getTimers()
Returns a map of all the timers in the registry and their names.- Returns:
- all the timers in the registry
-
getTimers
public abstract java.util.SortedMap<java.lang.String,Timer> getTimers(MetricFilter filter)
Returns a map of all the timers in the registry and their names which match the given filter.- Parameters:
filter
- the metric filter to match- Returns:
- all the timers in the registry
-
getMetrics
public abstract java.util.Map<java.lang.String,Metric> getMetrics()
Returns a map of all the metrics in the registry and their names.- Returns:
- all the metrics in the registry
-
getMetadata
public abstract java.util.Map<java.lang.String,Metadata> getMetadata()
Returns a map of all the metadata in the registry and their names.- Returns:
- all the metadata in the registry
-
-