From 1c093abaa28486077c99a23857554859be6abc58 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Fri, 24 Nov 2023 13:32:38 +0800 Subject: [PATCH 1/8] alarm threshold support prometheus task metrics --- README.md | 8 ++ README_CN.md | 8 ++ .../manager/service/impl/AppServiceImpl.java | 91 ++++++++++++++----- .../alert-setting.component.html | 2 +- .../routes/dashboard/dashboard.component.ts | 6 +- .../monitor-new/monitor-new.component.ts | 4 +- web-app/src/assets/i18n/en-US.json | 8 +- web-app/src/assets/i18n/zh-CN.json | 8 +- web-app/src/assets/i18n/zh-TW.json | 8 +- 9 files changed, 103 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 2bd560bfece..bc21b004ed0 100644 --- a/README.md +++ b/README.md @@ -432,5 +432,13 @@ HertzBeat is a top project under the [Dromara Open Source Community](https://dro - Thanks [吉实信息(构建全新的微波+光交易网络)](https://www.flarespeed.com) sponsored server node. - Thanks [蓝易云(全新智慧上云)](https://www.tsyvps.com/aff/BZBEGYLX) sponsored server node. +##### Open-Source Project Build From Open-Source + +> HertzBeat is built on so many great open source projects, thanks to them! + +- Java Spring SpringBoot Jpa Maven Assembly Netty Lombok Sureness Aviator Protobuf HttpClient Guava SnakeYaml JsonPath ... +- TypeScript Angular NG-ZORRO NG-ALAIN NodeJs Npm Html Less Echarts Rxjs ZoneJs MonacoEditor SlickCarousel Docusaurus ... + + ## 🛡️ License [`Apache License, Version 2.0`](https://www.apache.org/licenses/LICENSE-2.0.html) diff --git a/README_CN.md b/README_CN.md index 929766f07e2..8ab3ac8e9f4 100644 --- a/README_CN.md +++ b/README_CN.md @@ -436,5 +436,13 @@ HertzBeat 赫兹跳动是 [Dromara开源社区](https://dromara.org/) 下顶级 - 感谢 [吉实信息(构建全新的微波+光交易网络)](https://www.flarespeed.com) 赞助服务器采集节点 - 感谢 [蓝易云(全新智慧上云)](https://www.tsyvps.com/aff/BZBEGYLX) 赞助服务器采集节点 +##### Open-Source Project Build From Open-Source + +> HertzBeat is built on so many great open source projects, thanks to them! + +- Java Spring SpringBoot Jpa Maven Assembly Netty Lombok Sureness Aviator Protobuf HttpClient Guava SnakeYaml JsonPath ... +- TypeScript Angular NG-ZORRO NG-ALAIN NodeJs Npm Html Less Echarts Rxjs ZoneJs MonacoEditor SlickCarousel Docusaurus ... + + ## 🛡️ License [`Apache License, Version 2.0`](https://www.apache.org/licenses/LICENSE-2.0.html) diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java index 28be1786069..c1fa798023f 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java @@ -26,6 +26,7 @@ import org.dromara.hertzbeat.common.entity.job.Configmap; import org.dromara.hertzbeat.common.entity.job.Job; import org.dromara.hertzbeat.common.entity.job.Metrics; +import org.dromara.hertzbeat.common.entity.manager.Monitor; import org.dromara.hertzbeat.common.entity.manager.Param; import org.dromara.hertzbeat.common.entity.manager.ParamDefine; import org.dromara.hertzbeat.common.entity.message.CollectRep; @@ -247,7 +248,7 @@ public Map getI18nResources(String lang) { @Override public List getAllAppHierarchy(String lang) { - List hierarchies = new LinkedList<>(); + LinkedList hierarchies = new LinkedList<>(); for (var job : appDefines.values()) { // todo 暂时先过滤掉push以解决前端问题,待后续设计优化后放开 if (DispatchConstants.PROTOCOL_PUSH.equalsIgnoreCase(job.getApp())) { @@ -264,36 +265,80 @@ public List getAllAppHierarchy(String lang) { } } List hierarchyMetricList = new LinkedList<>(); - if (job.getMetrics() != null) { - for (var metrics : job.getMetrics()) { - var hierarchyMetric = new Hierarchy(); - hierarchyMetric.setValue(metrics.getName()); - var metricsI18nName = CommonUtil.getLangMappingValueFromI18nMap(lang, metrics.getI18n()); - hierarchyMetric.setLabel(metricsI18nName != null ? metricsI18nName : metrics.getName()); - List hierarchyFieldList = new LinkedList<>(); - if (metrics.getFields() != null) { - for (var field : metrics.getFields()) { - var hierarchyField = new Hierarchy(); - hierarchyField.setValue(field.getField()); - var metricI18nName = CommonUtil.getLangMappingValueFromI18nMap(lang, field.getI18n()); - hierarchyField.setLabel(metricI18nName != null ? metricI18nName : field.getField()); - hierarchyField.setIsLeaf(true); - // for metric - hierarchyField.setType(field.getType()); - hierarchyField.setUnit(field.getUnit()); - hierarchyFieldList.add(hierarchyField); - } + if (DispatchConstants.PROTOCOL_PROMETHEUS.equalsIgnoreCase(job.getApp())) { + List monitors = monitorDao.findMonitorsByAppEquals(job.getApp()); + for (Monitor monitor : monitors) { + List metricsDataList = warehouseService.queryMonitorMetricsData(monitor.getId()); + for (CollectRep.MetricsData metricsData : metricsDataList) { + var hierarchyMetric = new Hierarchy(); + hierarchyMetric.setValue(metricsData.getMetrics()); + hierarchyMetric.setLabel(metricsData.getMetrics()); + List hierarchyFieldList = metricsData.getFieldsList().stream() + .map(item -> { + var hierarchyField = new Hierarchy(); + hierarchyField.setValue(item.getName()); + hierarchyField.setLabel(item.getName()); + hierarchyField.setIsLeaf(true); + hierarchyField.setType((byte)item.getType()); + hierarchyField.setUnit(item.getUnit()); + return hierarchyField; + }).collect(Collectors.toList()); hierarchyMetric.setChildren(hierarchyFieldList); + // combine Hierarchy Metrics + combineHierarchyMetrics(hierarchyMetricList, hierarchyMetric); + } + } + hierarchyApp.setChildren(hierarchyMetricList); + hierarchies.addFirst(hierarchyApp); + } else { + if (job.getMetrics() != null) { + for (var metrics : job.getMetrics()) { + var hierarchyMetric = new Hierarchy(); + hierarchyMetric.setValue(metrics.getName()); + var metricsI18nName = CommonUtil.getLangMappingValueFromI18nMap(lang, metrics.getI18n()); + hierarchyMetric.setLabel(metricsI18nName != null ? metricsI18nName : metrics.getName()); + List hierarchyFieldList = new LinkedList<>(); + if (metrics.getFields() != null) { + for (var field : metrics.getFields()) { + var hierarchyField = new Hierarchy(); + hierarchyField.setValue(field.getField()); + var metricI18nName = CommonUtil.getLangMappingValueFromI18nMap(lang, field.getI18n()); + hierarchyField.setLabel(metricI18nName != null ? metricI18nName : field.getField()); + hierarchyField.setIsLeaf(true); + // for metric + hierarchyField.setType(field.getType()); + hierarchyField.setUnit(field.getUnit()); + hierarchyFieldList.add(hierarchyField); + } + hierarchyMetric.setChildren(hierarchyFieldList); + } + hierarchyMetricList.add(hierarchyMetric); } - hierarchyMetricList.add(hierarchyMetric); } + hierarchyApp.setChildren(hierarchyMetricList); + hierarchies.add(hierarchyApp); } - hierarchyApp.setChildren(hierarchyMetricList); - hierarchies.add(hierarchyApp); } return hierarchies; } + private void combineHierarchyMetrics(List hierarchyMetricList, Hierarchy hierarchyMetric) { + Optional preHierarchyOptional = hierarchyMetricList.stream() + .filter(item -> item.getValue().equals(hierarchyMetric.getValue())).findFirst(); + if (preHierarchyOptional.isPresent()) { + Hierarchy preHierarchy = preHierarchyOptional.get(); + List children = preHierarchy.getChildren(); + Set childrenKey = children.stream().map(Hierarchy::getValue).collect(Collectors.toSet()); + for (Hierarchy child : hierarchyMetric.getChildren()) { + if (!childrenKey.contains(child.getValue())) { + children.add(child); + } + } + } else { + hierarchyMetricList.add(hierarchyMetric); + } + } + @Override public Map getAllAppDefines() { return appDefines; 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 4a218f4c199..d258248ef68 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 @@ -15,7 +15,7 @@