org.apache.kafka.common.metrics.stats
Class SampledStat

java.lang.Object
  extended by org.apache.kafka.common.metrics.stats.SampledStat
All Implemented Interfaces:
Measurable, MeasurableStat, Stat
Direct Known Subclasses:
Avg, Count, Max, Min, Percentiles, Rate.SampledTotal

public abstract class SampledStat
extends java.lang.Object
implements MeasurableStat

A SampledStat records a single scalar value measured over one or more samples. Each sample is recorded over a configurable window. The window can be defined by number of events or ellapsed time (or both, if both are given the window is complete when either the event count or ellapsed time criterion is met).

All the samples are combined to produce the measurement. When a window is complete the oldest sample is cleared and recycled to begin recording the next sample. Subclasses of this class define different statistics measured using this basic pattern.


Nested Class Summary
protected static class SampledStat.Sample
           
 
Field Summary
protected  java.util.List<SampledStat.Sample> samples
           
 
Constructor Summary
SampledStat(double initialValue)
           
 
Method Summary
abstract  double combine(java.util.List<SampledStat.Sample> samples, MetricConfig config, long now)
           
 SampledStat.Sample current(long timeMs)
           
 double measure(MetricConfig config, long now)
          Measure this quantity and return the result as a double
protected  SampledStat.Sample newSample(long timeMs)
           
 SampledStat.Sample oldest(long now)
           
protected  void purgeObsoleteSamples(MetricConfig config, long now)
           
 void record(MetricConfig config, double value, long timeMs)
          Record the given value
protected abstract  void update(SampledStat.Sample sample, MetricConfig config, double value, long timeMs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

samples

protected java.util.List<SampledStat.Sample> samples
Constructor Detail

SampledStat

public SampledStat(double initialValue)
Method Detail

record

public void record(MetricConfig config,
                   double value,
                   long timeMs)
Description copied from interface: Stat
Record the given value

Specified by:
record in interface Stat
Parameters:
config - The configuration to use for this metric
value - The value to record
timeMs - The POSIX time in milliseconds this value occurred

newSample

protected SampledStat.Sample newSample(long timeMs)

measure

public double measure(MetricConfig config,
                      long now)
Description copied from interface: Measurable
Measure this quantity and return the result as a double

Specified by:
measure in interface Measurable
Parameters:
config - The configuration for this metric
now - The POSIX time in milliseconds the measurement is being taken
Returns:
The measured value

current

public SampledStat.Sample current(long timeMs)

oldest

public SampledStat.Sample oldest(long now)

update

protected abstract void update(SampledStat.Sample sample,
                               MetricConfig config,
                               double value,
                               long timeMs)

combine

public abstract double combine(java.util.List<SampledStat.Sample> samples,
                               MetricConfig config,
                               long now)

purgeObsoleteSamples

protected void purgeObsoleteSamples(MetricConfig config,
                                    long now)