Class IntervalMetric


  • public class IntervalMetric
    extends 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
    • Field Detail

      • DEFAULT_INTERVALS

        public static final long[] DEFAULT_INTERVALS
    • Constructor Detail

      • IntervalMetric

        public IntervalMetric​(@NotNull
                              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
                              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 List<Float> getRate()
        Returns:
        list of current rate of the metric (amount per second) for all time intervals
      • getFormattedRate

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

        @NotNull
        public String getDescription()
        Returns:
        metric description