Class 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.

    • 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
    • Constructor Detail

      • CollectorRegistry

        public CollectorRegistry()
      • CollectorRegistry

        public CollectorRegistry​(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 where sampleNameFilter.test(name) returns true for each name in Collector.MetricFamilySamples.getNames().
        Parameters:
        sampleNameFilter - may be null, 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.