[alerter,webapp] 告警阈值触发表达式优化新增自定义equals函数,告警配置页面完善tip
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
package com.usthe.alert;
|
||||
|
||||
import com.googlecode.aviator.AviatorEvaluator;
|
||||
import com.googlecode.aviator.runtime.function.AbstractFunction;
|
||||
import com.googlecode.aviator.runtime.type.AviatorBoolean;
|
||||
import com.googlecode.aviator.runtime.type.AviatorObject;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tomsun28
|
||||
* @date 2021/11/3 12:55
|
||||
@@ -17,6 +22,31 @@ public class AlerterConfiguration {
|
||||
public void configAviatorEvaluator() {
|
||||
// 配置AviatorEvaluator使用LRU缓存编译后的表达式
|
||||
AviatorEvaluator.getInstance()
|
||||
.useLRUExpressionCache(AVIATOR_LRU_CACHE_SIZE);
|
||||
.useLRUExpressionCache(AVIATOR_LRU_CACHE_SIZE)
|
||||
.addFunction(new StrEqualFunction());
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义aviator判断字符串是否相等函数
|
||||
*/
|
||||
private static class StrEqualFunction extends AbstractFunction {
|
||||
@Override
|
||||
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
|
||||
if (arg1 == null || arg2 == null) {
|
||||
return AviatorBoolean.valueOf(false);
|
||||
}
|
||||
Object leftTmp = arg1.getValue(env);
|
||||
Object rightTmp = arg2.getValue(env);
|
||||
if (leftTmp == null || rightTmp == null) {
|
||||
return AviatorBoolean.valueOf(false);
|
||||
}
|
||||
String left = String.valueOf(leftTmp);
|
||||
String right = String.valueOf(rightTmp);
|
||||
return AviatorBoolean.valueOf(left.equalsIgnoreCase(right));
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "equals";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.usthe.alert.calculate;
|
||||
|
||||
import com.googlecode.aviator.AviatorEvaluator;
|
||||
import com.googlecode.aviator.Expression;
|
||||
import com.usthe.alert.AlerterProperties;
|
||||
import com.usthe.alert.AlerterWorkerPool;
|
||||
import com.usthe.alert.AlerterDataQueue;
|
||||
import com.usthe.alert.entrance.KafkaDataConsume;
|
||||
@@ -116,7 +115,7 @@ public class CalculateAlarm {
|
||||
List<CollectRep.Field> fields = metricsData.getFieldsList();
|
||||
Map<String, Object> fieldValueMap = new HashMap<>(16);
|
||||
fieldValueMap.put("app", app);
|
||||
fieldValueMap.put("metric", metrics);
|
||||
fieldValueMap.put("metrics", metrics);
|
||||
for (CollectRep.ValueRow valueRow : metricsData.getValuesList()) {
|
||||
if (!valueRow.getColumnsList().isEmpty()) {
|
||||
String instance = valueRow.getInstance();
|
||||
@@ -128,6 +127,7 @@ public class CalculateAlarm {
|
||||
for (int index = 0; index < valueRow.getColumnsList().size(); index++) {
|
||||
String valueStr = valueRow.getColumns(index);
|
||||
CollectRep.Field field = fields.get(index);
|
||||
fieldValueMap.put("metric", field.getName());
|
||||
if (field.getType() == CommonConstants.TYPE_NUMBER) {
|
||||
Double doubleValue = CommonUtil.parseDoubleStr(valueStr);
|
||||
if (doubleValue != null) {
|
||||
|
||||
Reference in New Issue
Block a user