Class SimpleCollector<Child>

  • Direct Known Subclasses:
    Counter, Enumeration, Gauge, Histogram, Info, Summary

    public abstract class SimpleCollector<Child>
    extends Collector
    Common functionality for Gauge, Counter, Summary and Histogram.

    This class handles common initialization and label logic for the standard metrics. You should never subclass this class.

    Initialization

    After calling build() on a subclass, name, help, labelNames, namespace and subsystem can be called to configure the Collector. These return this to allow calls to be chained. Once configured, call create (which is also called by register).

    The fullname of the metric is namespace_subsystem_name, but only name is required.

    Labels

    labelNames specifies which (if any) labels the metrics will have, and labels(java.lang.String...) returns the Child of the metric that represents that particular set of labels. Gauge, Counter and Summary all offer convenience methods to avoid needing to call labels(java.lang.String...) for metrics with no labels.

    remove(java.lang.String...) and clear() can be used to remove children.

    Warning #1: Metrics that don't always export something are difficult to monitor, if you know in advance what labels will be in use you should initialise them be calling labels(java.lang.String...). This is done for you for metrics with no labels.

    Warning #2: While labels are very powerful, avoid overly granular metric labels. The combinatorial explosion of breaking out a metric in many dimensions can produce huge numbers of timeseries, which will then take longer and more resources to process.

    As a rule of thumb aim to keep the cardinality of metrics below ten, and limit where the cardinality exceeds that value. For example rather than breaking out latency by customer and endpoint in one metric, you might have two metrics with one breaking out by each. If the cardinality is in the hundreds, you may wish to consider removing the breakout by one of the dimensions altogether.