Class StatMetric

  • All Implemented Interfaces:
    java.io.Serializable

    @ThreadSafe
    public class StatMetric
    extends java.lang.Object
    implements java.io.Serializable
    A StatMetric keeps track of various statistics for one metric. For instance, the Metric might be "Requests". The statistics that can be kept are:
    1. Total
    2. Average Duration
    3. Max Duration
    4. Min Duration
    5. Throughput
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  StatMetric.Metric  
    • Constructor Summary

      Constructors 
      Constructor Description
      StatMetric()
      Creates a StatMetric that tracks averages in TimeUnit.SECONDS.
      StatMetric​(java.util.concurrent.TimeUnit timeUnit)  
      StatMetric​(java.util.concurrent.TimeUnit timeUnit, int nRequiredForAverage)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      double getAvg()
      The average duration (in seconds) for this metric.
      long getHits()
      Deprecated.
      double getLast()
      The last duration in seconds.
      long getLastUpdate()
      The last timestamp that this statmetric was updated.
      double getMax()
      The maximum duration (in seconds) ever witnessed for this metric.
      java.lang.Object getMetric​(StatMetric.Metric metric)  
      double getMin()
      The minimum duration (in seconds) ever witnessed for this metric.
      double getThroughput()
      The current throughput for this metric (hits/second), or -1 if the metric is idle.
      java.util.concurrent.TimeUnit getTimeUnit()  
      long getTotal()
      The total number of occurrences for this metric.
      static void main​(java.lang.String[] args)  
      protected void onSetThroughput​(double throughput)
      Called when the throughput is updated.
      void setTimeBetweenThroughputCalcs​(int timeBetweenThroughputCalcs)
      Set the amount of time that must pass between successive calculations of the throughput.
      void setTimeUnit​(java.util.concurrent.TimeUnit timeUnit)  
      java.lang.String toString()  
      void update​(long startTime)  
      void update​(long startTime, int count)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • StatMetric

        public StatMetric()
        Creates a StatMetric that tracks averages in TimeUnit.SECONDS.
      • StatMetric

        public StatMetric​(java.util.concurrent.TimeUnit timeUnit)
        Parameters:
        timeUnit - TimeUnit to use. Only TimeUnit.MILLISECONDS or TimeUnit.SECONDS.
      • StatMetric

        public StatMetric​(java.util.concurrent.TimeUnit timeUnit,
                          int nRequiredForAverage)
        Parameters:
        timeUnit - TimeUnit to use. Only TimeUnit.MILLISECONDS or TimeUnit.SECONDS.
        nRequiredForAverage - The number of calls to update() required to compute an average. Once reached, the average is computed using the last N values.
    • Method Detail

      • setTimeBetweenThroughputCalcs

        public void setTimeBetweenThroughputCalcs​(int timeBetweenThroughputCalcs)
        Set the amount of time that must pass between successive calculations of the throughput.
      • update

        public void update​(long startTime)
      • update

        public void update​(long startTime,
                           int count)
      • onSetThroughput

        protected void onSetThroughput​(double throughput)
        Called when the throughput is updated. Override if desired.
      • getAvg

        public double getAvg()
        The average duration (in seconds) for this metric.
      • getHits

        @Deprecated
        public long getHits()
        Deprecated.
      • getTotal

        public long getTotal()
        The total number of occurrences for this metric.
      • getMax

        public double getMax()
        The maximum duration (in seconds) ever witnessed for this metric.
      • getMin

        public double getMin()
        The minimum duration (in seconds) ever witnessed for this metric.
      • getLast

        public double getLast()
        The last duration in seconds.
      • getThroughput

        public double getThroughput()
        The current throughput for this metric (hits/second), or -1 if the metric is idle.
      • getLastUpdate

        public long getLastUpdate()
        The last timestamp that this statmetric was updated.
        Returns:
        The last System.currentTimeMillis() that this StatMetric had update() called on it.
      • getTimeUnit

        public java.util.concurrent.TimeUnit getTimeUnit()
      • setTimeUnit

        public void setTimeUnit​(java.util.concurrent.TimeUnit timeUnit)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)