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.
    Since:
    9.1.2
    • Nested Class Summary

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

      Fields 
      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

      • DEFAULT_INTERVALS

        public static final long[] DEFAULT_INTERVALS
    • Constructor Detail

      • IntervalMetric

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

        public IntervalMetric​(@NotNull
                              IntervalMetric.ValueType valueType,
                              long[] intervals,
                              @NotNull
                              java.lang.String description,
                              @Nullable
                              TimeService timeService)
        Creates metric.
        Parameters:
        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
        Parameters:
        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.
        Parameters:
        idx - index of the interval in interval array
        Returns:
        see above
      • getLastModified

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

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

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

        @NotNull
        public java.lang.String getDescription()
        Returns:
        metric description