Class Collector
- java.lang.Object
-
- io.prometheus.client.Collector
-
- Direct Known Subclasses:
BufferPoolsExports
,CacheMetricsCollector
,CacheMetricsCollector
,ClassLoadingExports
,GarbageCollectorExports
,JettyStatisticsCollector
,MemoryAllocationExports
,MemoryPoolsExports
,QueuedThreadPoolStatisticsCollector
,SimpleCollector
,StandardExports
,ThreadExports
,VersionInfoExports
public abstract class Collector extends java.lang.Object
A collector for a set of metrics.Normal users should use
Gauge
,Counter
,Summary
andHistogram
.Subclasssing Collector is for advanced uses, such as proxying metrics from another monitoring system. It is it the responsibility of subclasses to ensure they produce valid metrics.
- See Also:
- Exposition formats.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Collector.Describable
static class
Collector.MetricFamilySamples
A metric, and all of its samples.static class
Collector.Type
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
METRIC_LABEL_NAME_RE
private static java.util.regex.Pattern
METRIC_NAME_RE
static double
MILLISECONDS_PER_SECOND
Number of milliseconds in a second.static double
NANOSECONDS_PER_SECOND
Number of nanoseconds in a second.private static java.util.regex.Pattern
RESERVED_METRIC_LABEL_NAME_RE
-
Constructor Summary
Constructors Constructor Description Collector()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static void
checkMetricLabelName(java.lang.String name)
Throw an exception if the metric label name is invalid.protected static void
checkMetricName(java.lang.String name)
Throw an exception if the metric name is invalid.abstract java.util.List<Collector.MetricFamilySamples>
collect()
Return all metrics of this Collector.java.util.List<Collector.MetricFamilySamples>
collect(Predicate<java.lang.String> sampleNameFilter)
Likecollect()
, but the result should only containMetricFamilySamples
wheresampleNameFilter.test(name)
istrue
for at least one Sample name.static java.lang.String
doubleToGoString(double d)
Convert a double to its string representation in Go.<T extends Collector>
Tregister()
Register the Collector with the default registry.<T extends Collector>
Tregister(CollectorRegistry registry)
Register the Collector with the given registry.static java.lang.String
sanitizeMetricName(java.lang.String metricName)
Sanitize metric name
-
-
-
Field Detail
-
NANOSECONDS_PER_SECOND
public static final double NANOSECONDS_PER_SECOND
Number of nanoseconds in a second.- See Also:
- Constant Field Values
-
MILLISECONDS_PER_SECOND
public static final double MILLISECONDS_PER_SECOND
Number of milliseconds in a second.- See Also:
- Constant Field Values
-
METRIC_NAME_RE
private static final java.util.regex.Pattern METRIC_NAME_RE
-
METRIC_LABEL_NAME_RE
private static final java.util.regex.Pattern METRIC_LABEL_NAME_RE
-
RESERVED_METRIC_LABEL_NAME_RE
private static final java.util.regex.Pattern RESERVED_METRIC_LABEL_NAME_RE
-
-
Method Detail
-
collect
public abstract java.util.List<Collector.MetricFamilySamples> collect()
Return all metrics of this Collector.
-
collect
public java.util.List<Collector.MetricFamilySamples> collect(Predicate<java.lang.String> sampleNameFilter)
Likecollect()
, but the result should only containMetricFamilySamples
wheresampleNameFilter.test(name)
istrue
for at least one Sample name.The default implementation first collects all
MetricFamilySamples
and then discards the ones wheresampleNameFilter.test(name)
returnsfalse
for all names inCollector.MetricFamilySamples.getNames()
. To improve performance, collector implementations should override this method to preventMetricFamilySamples
from being collected if they will be discarded anyways. SeeThreadExports
for an example.Note that the resulting List may contain
MetricFamilySamples
where some Sample names returntrue
forsampleNameFilter.test(name)
but some Sample names returnfalse
. This is ok, because before we produce the output format we will callCollector.MetricFamilySamples.filter(Predicate)
to strip all Samples wheresampleNameFilter.test(name)
returnsfalse
.- Parameters:
sampleNameFilter
- may benull
, indicating that all metrics should be collected.
-
register
public <T extends Collector> T register()
Register the Collector with the default registry.
-
register
public <T extends Collector> T register(CollectorRegistry registry)
Register the Collector with the given registry.
-
checkMetricName
protected static void checkMetricName(java.lang.String name)
Throw an exception if the metric name is invalid.
-
sanitizeMetricName
public static java.lang.String sanitizeMetricName(java.lang.String metricName)
Sanitize metric name
-
checkMetricLabelName
protected static void checkMetricLabelName(java.lang.String name)
Throw an exception if the metric label name is invalid.
-
doubleToGoString
public static java.lang.String doubleToGoString(double d)
Convert a double to its string representation in Go.
-
-