From cc66efebf360e65c98411000a3810b78fe41c95f Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sun, 19 Dec 2021 10:52:54 +0800 Subject: [PATCH] =?UTF-8?q?[alerter,webapp]=20=E5=91=8A=E8=AD=A6=E9=98=88?= =?UTF-8?q?=E5=80=BC=E8=A7=A6=E5=8F=91=E8=A1=A8=E8=BE=BE=E5=BC=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89equals?= =?UTF-8?q?=E5=87=BD=E6=95=B0,=E5=91=8A=E8=AD=A6=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=AE=8C=E5=96=84tip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/usthe/alert/AlerterConfiguration.java | 32 +++++++- .../usthe/alert/calculate/CalculateAlarm.java | 4 +- .../alert-setting.component.html | 77 ++++++++++++++----- 3 files changed, 91 insertions(+), 22 deletions(-) diff --git a/alerter/src/main/java/com/usthe/alert/AlerterConfiguration.java b/alerter/src/main/java/com/usthe/alert/AlerterConfiguration.java index 39f449a..3fc3964 100644 --- a/alerter/src/main/java/com/usthe/alert/AlerterConfiguration.java +++ b/alerter/src/main/java/com/usthe/alert/AlerterConfiguration.java @@ -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 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"; + } } } diff --git a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java index 6b8977b..7a471fb 100644 --- a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java +++ b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java @@ -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 fields = metricsData.getFieldsList(); Map 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) { diff --git a/web-app/src/app/routes/alert/alert-setting/alert-setting.component.html b/web-app/src/app/routes/alert/alert-setting/alert-setting.component.html index 533d34a..7ff723d 100644 --- a/web-app/src/app/routes/alert/alert-setting/alert-setting.component.html +++ b/web-app/src/app/routes/alert/alert-setting/alert-setting.component.html @@ -128,7 +128,7 @@ @@ -137,25 +137,30 @@ instance : 所属行实例值 + + 支持操作符函数 : equals(str1,str2), ==, <, <=, >, >=, !=, ( ), +, -, &&, || + - 阈值触发表达式 + + 阈值触发表达式 + - 告警级别 + + 告警级别 - 触发次数 + + 触发次数 + + name="duration" id="duration"> - 通知模版 + + + + + + $(metric) : 选中的指标对象名称 + + + $({{cascadeValues[2]}}) : 选中的指标对象值 + + + $(instance) : 所在行实例值 + + + $(app) : 所属监控类型名称 + + + $(metrics) : 所属监控指标组名称 + + + + + + + + + 通知模版 + - + - 全局默认 + + 全局默认 + - 启用告警 + + 启用告警 + @@ -234,12 +275,10 @@ - - 监控 + + 未关联监控 + 已关联监控