Class Collector

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

      • Collector

        public Collector()
    • Method Detail

      • collect

        public java.util.List<Collector.MetricFamilySamples> collect​(Predicate<java.lang.String> sampleNameFilter)
        Like collect(), but the result should only contain MetricFamilySamples where sampleNameFilter.test(name) is true for at least one Sample name.

        The default implementation first collects all MetricFamilySamples and then discards the ones where sampleNameFilter.test(name) returns false for all names in Collector.MetricFamilySamples.getNames(). To improve performance, collector implementations should override this method to prevent MetricFamilySamples from being collected if they will be discarded anyways. See ThreadExports for an example.

        Note that the resulting List may contain MetricFamilySamples where some Sample names return true for sampleNameFilter.test(name) but some Sample names return false. This is ok, because before we produce the output format we will call Collector.MetricFamilySamples.filter(Predicate) to strip all Samples where sampleNameFilter.test(name) returns false.

        Parameters:
        sampleNameFilter - may be null, 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.