Class IntervalMetric

  • public class IntervalMetric
    extends java.lang.Object
    This class holds N last values for some metric gathered during specified intervals. For instance, if there is some metric, like number of bytes written to disk, instance of this class can be created to hold values for this metric during the last 1, 5 and 10 minutes.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  IntervalMetric.ValueType
      Represents type of the metric.
    • Field Summary

      Modifier and Type Field Description
      static long[] DEFAULT_INTERVALS  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long amount)
      Adds specified amount to the metric
      java.lang.String getDescription()  
      java.util.List<java.lang.String> getFormattedRate()  
      long getLastModified()  
      java.util.List<java.lang.Float> getRate()  
      long getValue​(int idx)
      Returns value of the metric for given interval index.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail


        public static final long[] DEFAULT_INTERVALS
    • Constructor Detail

      • IntervalMetric

        public IntervalMetric​(@NotNull
                              java.lang.String description)
        Creates metric with some human readable description
        description - description of the metric
      • IntervalMetric

        public IntervalMetric​(@NotNull
                              IntervalMetric.ValueType valueType,
                              long[] intervals,
                              java.lang.String description,
                              TimeService timeService)
        Creates metric.
        valueType - metric type, IntervalMetric.ValueType
        intervals - a number of intervals for this metric, each value of this array is time in milliseconds
        description - human readable description
        timeService - time service, it will be used to obtain current time; can be null, useful for tests
    • Method Detail

      • add

        public void add​(long amount)
        Adds specified amount to the metric
        amount - amount to add
      • getValue

        public long getValue​(int idx)
        Returns value of the metric for given interval index. Returns 0 if specified interval is not yet passed.
        idx - index of the interval in interval array
        see above
      • getLastModified

        public long getLastModified()
        time when add with positive amount was called last time, can be 0 if this never happened
      • getRate

        public java.util.List<java.lang.Float> getRate()
        list of current rate of the metric (amount per second) for all time intervals
      • getFormattedRate

        public java.util.List<java.lang.String> getFormattedRate()
        list of formatted rate of the metric for all time intervals
      • getDescription

        public java.lang.String getDescription()
        metric description