Class ValueFilterMap

java.lang.Object
com.codahale.metrics.riemann.ValueFilterMap

public class ValueFilterMap extends Object
Enables ValueFilters to be associated with measures reported by Metrics so that state can be computed based on values at report-generation time. The addFilter(Metric, String, ValueFilter) method associates a ValueFilter with a measure and the state methods compute what state should be reported based on the value of a measure.

For example, ValueFilterMap valueFilterMap = new ValueFilterMap(); valueFilterMap .addFilter(timer, ValueFilterMap.MAX, new ValueFilter.Builder("critical").withLower(50).build()) .addFilter(timer, ValueFilterMap.MEAN, new ValueFilter.Builder("warn") .withUpperExclusive(200).withLower(100).build()); Attaches filters to the mean and max values reported by timers so that state(timer, "max") will return "critical" if the max value reported by the timer is greater than or equal to 50 and state(timer, "mean") will return "warn" if the mean value is between 100 (inclusive) and 200 (exclusive). Filters are applied in the order they are added and the last one that applies wins. If no filter applies, state methods return "ok".

  • Field Details

  • Constructor Details

    • ValueFilterMap

      public ValueFilterMap()
  • Method Details

    • addFilter

      public ValueFilterMap addFilter(com.codahale.metrics.Metric metric, String measure, ValueFilter filter)
      Add a filter associated with the given measure for the given metric.
      Parameters:
      metric - metric instance reporting the measure that the filter applies to
      measure - name of the value reported by the metric that the filter applies to
      filter - ValueFilter instance that, if it applies, may determine the state reported for the measure
      Returns:
      a reference to *this (for fluent activation)
    • getFilterList

      public List<ValueFilter> getFilterList(com.codahale.metrics.Metric metric, String measure)
      Returns the list of filters that have been added to the given metric, measure pair.
      Parameters:
      metric - metric the measure belongs to
      measure - name of one of the values reported by the metric
      Returns:
      list of filters that should be applied when determining the state reported with the given measure
    • state

      public String state(com.codahale.metrics.Timer timer, String measure, TimeUnit durationUnit)
      Determines the state that should be reported with the given measure for the given timer instance.
      Parameters:
      timer - timer instance
      measure - name of the value reported by the timer whose reported state is sought
      durationUnit - TimeUnit to convert timer's native (nanosecond) measurements to
      Returns:
      state corresponding to the given measure
    • state

      public String state(com.codahale.metrics.Histogram histogram, String measure)
      Return the state that should be reported for the given measure, histogram pair.
      Parameters:
      histogram - histogram instance
      measure - name of a measure included in the histogram report
      Returns:
      the state associated to the current value of the measure in the histogram, or "ok" if there is no state mapped to this measure, histogram pair.
    • state

      public String state(com.codahale.metrics.Metered metered, String measure)
      Return the state that should be reported for the given measure, metered instance pair.
      Parameters:
      metered - metered instance
      measure - name of a measure included in the metered instance report
      Returns:
      the state associated to the current value of the measure in the metered instance, or "ok" if there is no state mapped to this measure, metered instance pair.
    • state

      public String state(com.codahale.metrics.Counter counter)
      Return the state that should be reported for the given counter, based on its value.
      Parameters:
      counter - Counter instance
      Returns:
      the state associated to the current value of the counter in the or "ok" if there is no state mapped to this Counter value.
    • clear

      public void clear(com.codahale.metrics.Metric metric)
      Clear all state mappings associated with the given Metric.
      Parameters:
      metric - Metric instance to clear mappings for
    • clear

      public void clear()
      Clear all mappings for all Metric instances.