MultiMetricTotalAggregateBasedRollupFunction implements RollupThresholdFunction { @Override public boolean isAboveThreshold(MetricTimeSeries timeSeries) { Set<Long> timeWindowSet = timeSeries.getTimeWindowSet(); JexlEngine jexl = new JexlEngine(); JexlContext context = new MapContext(); Expression e = jexl.createExpression(this.thresholdExpr); for(String metricName : metricNames){ long sum = 0; for (Long timeWindow : timeWindowSet) { sum += timeSeries.get(timeWindow, metricName).longValue(); } context.set(metricName, sum); if (LOGGER.isDebugEnabled()) { LOGGER.debug(metricName + " = " + sum); } } return ((Boolean)e.evaluate(context)).booleanValue(); } MultiMetricTotalAggregateBasedRollupFunction(Map<String, String> params); @Override boolean isAboveThreshold(MetricTimeSeries timeSeries); @Override TimeGranularity getRollupAggregationGranularity();  }
@Test public void test1() throws Exception{ MetricTimeSeries series = generateSeries(); Map<String, String> thresholdFuncParams = Maps.newHashMap(); thresholdFuncParams.put("metricNames", "metric1,metric2"); thresholdFuncParams.put("thresholdExpr", "(metric1 > 5000 || metric2 > 5000)"); MultiMetricTotalAggregateBasedRollupFunction func = new MultiMetricTotalAggregateBasedRollupFunction(thresholdFuncParams); Assert.assertFalse(func.isAboveThreshold(series)); }
@Test public void test2() throws Exception{ MetricTimeSeries series = generateSeries(); Map<String, String> thresholdFuncParams = Maps.newHashMap(); thresholdFuncParams.put("metricNames", "metric1,metric2,metric3"); thresholdFuncParams.put("thresholdExpr", "(metric1 > 5000 || metric2 > 5000 || metric3 > 0)"); MultiMetricTotalAggregateBasedRollupFunction func = new MultiMetricTotalAggregateBasedRollupFunction(thresholdFuncParams); Assert.assertTrue(func.isAboveThreshold(series)); }