Class MeterView

  • All Implemented Interfaces:
    Meter, Metric, View

    @Internal
    public class MeterView
    extends Object
    implements Meter, View
    A MeterView provides an average rate of events per second over a given time period.

    The primary advantage of this class is that the rate is neither updated by the computing thread nor for every event. Instead, a history of counts is maintained that is updated in regular intervals by a background thread. From this history a rate is derived on demand, which represents the average rate of events over the given time span.

    Setting the time span to a low value reduces memory-consumption and will more accurately report short-term changes. The minimum value possible is View.UPDATE_INTERVAL_SECONDS. A high value in turn increases memory-consumption, since a longer history has to be maintained, but will result in smoother transitions between rates.

    The events are counted by a Counter.

    • Constructor Detail

      • MeterView

        public MeterView​(int timeSpanInSeconds)
      • MeterView

        public MeterView​(Counter counter)
      • MeterView

        public MeterView​(Counter counter,
                         int timeSpanInSeconds)
      • MeterView

        public MeterView​(Gauge<? extends Number> numberGauge)
    • Method Detail

      • markEvent

        public void markEvent()
        Description copied from interface: Meter
        Mark occurrence of an event.
        Specified by:
        markEvent in interface Meter
      • markEvent

        public void markEvent​(long n)
        Description copied from interface: Meter
        Mark occurrence of multiple events.
        Specified by:
        markEvent in interface Meter
        Parameters:
        n - number of events occurred
      • getCount

        public long getCount()
        Description copied from interface: Meter
        Get number of events marked on the meter.
        Specified by:
        getCount in interface Meter
        Returns:
        number of events marked on the meter
      • getRate

        public double getRate()
        Description copied from interface: Meter
        Returns the current rate of events per second.
        Specified by:
        getRate in interface Meter
        Returns:
        current rate of events per second
      • update

        public void update()
        Description copied from interface: View
        This method will be called regularly to update the metric.
        Specified by:
        update in interface View