Class AggregateMetricReader

  • All Implemented Interfaces:
    MetricReader

    public class AggregateMetricReader
    extends Object
    implements MetricReader
    A metric reader that aggregates values from a source reader, normally one that has been collecting data from many sources in the same form (like a scaled-out application). The source has metrics with names in the form *.*.counter.** and *.*.[anything].**, and the result has metric names in the form aggregate.count.** and aggregate.[anything].**. Counters are summed and anything else (i.e. gauges) are aggregated by choosing the most recent value.
    Since:
    1.3.0
    • Method Detail

      • setKeyPattern

        public void setKeyPattern​(String keyPattern)
        Pattern that tells the aggregator what to do with the keys from the source repository. The keys in the source repository are assumed to be period separated, and the pattern is in the same format, e.g. "d.d.k.d". The pattern segments are matched against the source keys and a rule is applied:
        • "d" means "discard" this key segment (useful for global prefixes like system identifiers, or aggregate keys a.k.a. physical identifiers)
        • "k" means "keep" it with no change (useful for logical identifiers like app names)
        Default is "d.d" (we assume there is a global prefix of length 2).
        Parameters:
        keyPattern - the keyPattern to set
      • setPrefix

        public void setPrefix​(String prefix)
        Prefix to apply to all output metrics. A period will be appended if not present in the provided value.
        Parameters:
        prefix - the prefix to use (default "aggregator.")
      • findOne

        public Metric<?> findOne​(String metricName)
        Description copied from interface: MetricReader
        Find an instance of the metric with the given name (usually the latest recorded value).
        Specified by:
        findOne in interface MetricReader
        Parameters:
        metricName - the name of the metric to find
        Returns:
        a metric value or null if there are none with that name
      • count

        public long count()
        Description copied from interface: MetricReader
        The number of metrics known to this reader.
        Specified by:
        count in interface MetricReader
        Returns:
        the number of metrics