Class Collector

  • Direct Known Subclasses:
    SimpleCollector

    public abstract class Collector
    extends Object
    A collector for a set of metrics.

    Normal users should use Gauge, Counter, Summary and Histogram.

    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.
    • Method Detail

      • collect

        public List<Collector.MetricFamilySamplescollect​(Predicate<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.
      • checkMetricName

        protected static void checkMetricName​(String name)
        Throw an exception if the metric name is invalid.
      • checkMetricLabelName

        protected static void checkMetricLabelName​(String name)
        Throw an exception if the metric label name is invalid.
      • doubleToGoString

        public static String doubleToGoString​(double d)
        Convert a double to its string representation in Go.