From 43d805cc5c137f540b6951a1fcdd1b9d87d89954 Mon Sep 17 00:00:00 2001 From: durant <826035498@qq.com> Date: Sun, 14 Apr 2024 16:59:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E7=9B=91=E6=8E=A7=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E6=94=AF=E6=8C=81=E7=9B=91=E6=8E=A7=E7=9B=AE=E6=A0=87?= =?UTF-8?q?;=20metric=5Fid=20=E6=A0=BC=E5=BC=8F=E5=8C=96;=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=91=8A=E8=AD=A6=E7=AD=96=E7=95=A5=20#3973?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_monitor/models/alarm.py | 29 ++++++++++++++----- ...\350\267\263\347\233\221\346\216\247.json" | 2 +- ...\350\267\263\347\233\221\346\216\247.json" | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/dbm-ui/backend/db_monitor/models/alarm.py b/dbm-ui/backend/db_monitor/models/alarm.py index af94e7e5ac..72a8efce95 100644 --- a/dbm-ui/backend/db_monitor/models/alarm.py +++ b/dbm-ui/backend/db_monitor/models/alarm.py @@ -24,7 +24,7 @@ from backend.components import BKMonitorV3Api from backend.configuration.constants import PLAT_BIZ_ID, DBType, SystemSettingsEnum from backend.configuration.models import SystemSettings -from backend.db_meta.models import DBModule +from backend.db_meta.models import AppMonitorTopo, DBModule from backend.db_monitor.constants import ( APP_PRIORITY, BK_MONITOR_SAVE_DISPATCH_GROUP_TEMPLATE, @@ -621,7 +621,7 @@ def patch_bk_biz_id(details): return details @staticmethod - def patch_target_and_metric_id(details): + def patch_target_and_metric_id(details, alert_source, db_type): """监控目标/自定义事件和指标需要渲染 metric_id: {bk_biz_id}_bkmoinitor_event_{event_data_id} """ @@ -631,13 +631,26 @@ def patch_target_and_metric_id(details): items = details["items"] # 事件类告警,无需设置告警目标,否则要求上报的数据必须携带服务实例id(告警目标匹配依据) for item in items: - # 去掉目标范围,支持跨业务告警 - item["target"] = [] + # 更新监控目标为db_type对应的cmdb拓扑 + item["target"] = ( + [ + [ + { + "field": "host_topo_node", + "method": "eq", + "value": [ + {"bk_inst_id": obj["bk_set_id"], "bk_obj_id": "set"} + for obj in AppMonitorTopo.get_set_by_dbtype(db_type=db_type) + ], + } + ] + ] + if alert_source == AlertSourceEnum.TIME_SERIES.value + else [] + ) + for query_config in item["query_configs"]: # data_type_label: time_series | event(自定义上报,需要填充data_id) - if query_config["data_type_label"] != "event": - continue - # 自定义事件/指标类告警,需要渲染模板变量 bkm_dbm_report_event = bkm_dbm_report["event"] bkm_dbm_report_metric = bkm_dbm_report["metric"] @@ -749,7 +762,7 @@ def patch_all(self): # other details = self.patch_bk_biz_id(details) - details = self.patch_target_and_metric_id(details) + details = self.patch_target_and_metric_id(details, self.alert_source, self.db_type) return details diff --git "a/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql crond\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" "b/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql crond\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" index a73e347dd9..0458ba4b0b 100644 --- "a/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql crond\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" +++ "b/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql crond\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" @@ -12,7 +12,7 @@ { "name": "COUNT(mysql_crond_heart_beat)", "no_data_config": { - "level": 1, + "level": 2, "continuous": "5", "is_enabled": true, "agg_dimension": [ diff --git "a/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql monitor\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" "b/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql monitor\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" index c1250414f7..e520391761 100644 --- "a/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql monitor\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" +++ "b/dbm-ui/backend/db_monitor/tpls/alarm/mysql/Mysql monitor\347\273\204\344\273\266\345\277\203\350\267\263\347\233\221\346\216\247.json" @@ -12,7 +12,7 @@ { "name": "COUNT(mysql_monitor_heart_beat)", "no_data_config": { - "level": 1, + "level": 2, "continuous": "5", "is_enabled": true, "agg_dimension": [