/** * @param predicate * @return a {@link ThresholdPredicate}. * @throws ThresholdRuleValidationError */ static ThresholdPredicate from(final String predicate) throws ThresholdRuleValidationError { for (final ThresholdPredicate p : ThresholdPredicate.values()) if (p.name.equals(predicate)) return p; throw new ThresholdRuleValidationError( "invalid rule specification: unsupported predicate: " + predicate); }
/** * Constructor. * * @param bean */ private ThresholdRequirement(final ThresholdRequirementBean bean) { this.thresholdValue = bean.getThreshold(); this.metric = bean.getMetric(); this.pred = ThresholdPredicate.from(bean.getPredicate()); this.foldMethod = bean.getAggregationMethod() != null ? ThresholdFold.from(bean.getAggregationMethod()) : null; }
/** * @param e the event to check for violation metrics. * @param filterUnits * @return the particular monitored metric violation or <code>null</code>, or <code>null</code>. */ Violation isViolated(final MonitoringEvent e, final List<String> filterUnits) { final double observedValue = (Double) e.get(metric); final boolean res = pred.perform(observedValue, thresholdValue); if (!res) return null; final ArrayList<String> applicable = new ArrayList<String>(filterUnits.size()); for (final String filterUnit : filterUnits) if (ThresholdRulesTraits.join(e).startsWith(filterUnit)) applicable.add(filterUnit); return new Violation(metric, thresholdValue, observedValue, applicable); }
/** * @param events the list of events to check for violation metrics. * @param filterUnits * @return the particular monitored metric violation or <code>null</code>, or <code>null</code>. */ Violation isViolated(final List<MonitoringEvent> events, final List<String> filterUnits) { // FIXME: should check specific filterUnit final double observedValue = performFold(events); final boolean res = pred.perform(observedValue, thresholdValue); if (!res) return null; final ArrayList<String> applicable = new ArrayList<String>(filterUnits.size()); for (final String filterUnit : filterUnits) for (final MonitoringEvent e : events) if (ThresholdRulesTraits.join(e).startsWith(filterUnit)) applicable.add(filterUnit); return new Violation(metric, thresholdValue, observedValue, null); }