Class AdditiveMetric

java.lang.Object
com.mongodb.kafka.connect.util.jmx.internal.AdditiveMetric
All Implemented Interfaces:
Metric

public class AdditiveMetric extends Object implements Metric
An AdditiveMetric is a measurement that may be taken periodically, with the sampled number being added to some total. This produces a number of values based on that periodic sampling: the number of samples, the total amount sampled, and the number of samples over some limit.

For example, we might sample the byte size of each message we receive, and the AdditiveMetric will track a count of the number of times a sample has been taken, the total number of bytes received, and the number of messages sampled that exceeded certain limits. Another example is the amount of time that some operation takes.

The measured statistics can be compared against each other over a period of time to derive other statistics. For example, the total can be divided by the count to determine the average, or the number of samples over some limit may be divided by the count to determine the percentage of samples over that limit.

Metrics are intended to be sampled periodically and stored by some external component. Using that component to subtract some earlier time T1 from some later time T2 can provide statistics over that interval of time.

The sampled numbers are generally assumed to be positive; if negative numbers are used, it may become difficult for the consuming user to make certain inferences.

  • Constructor Details

    • AdditiveMetric

      public AdditiveMetric(String name, String unit, long[] limits)
  • Method Details

    • sample

      public void sample(long n)
      Description copied from interface: Metric
      Take the measurement.
      Specified by:
      sample in interface Metric
      Parameters:
      n - The value of the measurement.
    • emit

      public void emit(Consumer<MetricValue> consumer)
      Specified by:
      emit in interface Metric
      Parameters:
      consumer - A callback receiving a MetricValue that may be used to obtain the name and most recent value.