Package io.prometheus.client
Class CollectorRegistry
- java.lang.Object
-
- io.prometheus.client.CollectorRegistry
-
public class CollectorRegistry extends java.lang.Object
A registry of Collectors.The majority of users should use the
defaultRegistry
, rather than instantiating their own.Creating a registry other than the default is primarily useful for unittests, or pushing a subset of metrics to the Pushgateway from batch jobs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
CollectorRegistry.MetricFamilySamplesEnumeration
-
Field Summary
Fields Modifier and Type Field Description private boolean
autoDescribe
private java.util.Map<Collector,java.util.List<java.lang.String>>
collectorsToNames
static CollectorRegistry
defaultRegistry
The default registry.private java.lang.Object
namesCollectorsLock
private java.util.Map<java.lang.String,Collector>
namesToCollectors
-
Constructor Summary
Constructors Constructor Description CollectorRegistry()
CollectorRegistry(boolean autoDescribe)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
assertNoDuplicateNames(Collector m, java.util.List<java.lang.String> names)
void
clear()
Unregister all Collectors.private java.util.List<java.lang.String>
collectorNames(Collector m)
private java.util.Set<Collector>
collectors()
A snapshot of the current collectors.java.util.Enumeration<Collector.MetricFamilySamples>
filteredMetricFamilySamples(Predicate<java.lang.String> sampleNameFilter)
Enumeration of metrics wheresampleNameFilter.test(name)
returnstrue
for eachname
inCollector.MetricFamilySamples.getNames()
.java.util.Enumeration<Collector.MetricFamilySamples>
filteredMetricFamilySamples(java.util.Set<java.lang.String> includedNames)
Enumeration of metrics matching the specified names.java.lang.Double
getSampleValue(java.lang.String name)
Returns the given value, or null if it doesn't exist.java.lang.Double
getSampleValue(java.lang.String name, java.lang.String[] labelNames, java.lang.String[] labelValues)
Returns the given value, or null if it doesn't exist.java.util.Enumeration<Collector.MetricFamilySamples>
metricFamilySamples()
Enumeration of metrics of all registered collectors.void
register(Collector m)
Register a Collector.void
unregister(Collector m)
Unregister a Collector.
-
-
-
Field Detail
-
defaultRegistry
public static final CollectorRegistry defaultRegistry
The default registry.
-
namesCollectorsLock
private final java.lang.Object namesCollectorsLock
-
collectorsToNames
private final java.util.Map<Collector,java.util.List<java.lang.String>> collectorsToNames
-
namesToCollectors
private final java.util.Map<java.lang.String,Collector> namesToCollectors
-
autoDescribe
private final boolean autoDescribe
-
-
Method Detail
-
register
public void register(Collector m)
Register a Collector.A collector can be registered to multiple CollectorRegistries.
-
assertNoDuplicateNames
private void assertNoDuplicateNames(Collector m, java.util.List<java.lang.String> names)
-
unregister
public void unregister(Collector m)
Unregister a Collector.
-
clear
public void clear()
Unregister all Collectors.
-
collectors
private java.util.Set<Collector> collectors()
A snapshot of the current collectors.
-
collectorNames
private java.util.List<java.lang.String> collectorNames(Collector m)
-
metricFamilySamples
public java.util.Enumeration<Collector.MetricFamilySamples> metricFamilySamples()
Enumeration of metrics of all registered collectors.
-
filteredMetricFamilySamples
public java.util.Enumeration<Collector.MetricFamilySamples> filteredMetricFamilySamples(java.util.Set<java.lang.String> includedNames)
Enumeration of metrics matching the specified names.Note that the provided set of names will be matched against the time series name and not the metric name. For instance, to retrieve all samples from a histogram, you must include the '_count', '_sum' and '_bucket' names.
-
filteredMetricFamilySamples
public java.util.Enumeration<Collector.MetricFamilySamples> filteredMetricFamilySamples(Predicate<java.lang.String> sampleNameFilter)
Enumeration of metrics wheresampleNameFilter.test(name)
returnstrue
for eachname
inCollector.MetricFamilySamples.getNames()
.- Parameters:
sampleNameFilter
- may benull
, indicating that the enumeration should contain all metrics.
-
getSampleValue
public java.lang.Double getSampleValue(java.lang.String name)
Returns the given value, or null if it doesn't exist.This is inefficient, and intended only for use in unittests.
-
getSampleValue
public java.lang.Double getSampleValue(java.lang.String name, java.lang.String[] labelNames, java.lang.String[] labelValues)
Returns the given value, or null if it doesn't exist.This is inefficient, and intended only for use in unittests.
-
-