Skip to content

Commit

Permalink
feat(backend): 监控策略支持监控目标; metric_id 格式化; 更新告警策略 #3973
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 committed Apr 15, 2024
1 parent 6d554d8 commit 43d805c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
29 changes: 21 additions & 8 deletions dbm-ui/backend/db_monitor/models/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
"""
Expand All @@ -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"]
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"name": "COUNT(mysql_crond_heart_beat)",
"no_data_config": {
"level": 1,
"level": 2,
"continuous": "5",
"is_enabled": true,
"agg_dimension": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"name": "COUNT(mysql_monitor_heart_beat)",
"no_data_config": {
"level": 1,
"level": 2,
"continuous": "5",
"is_enabled": true,
"agg_dimension": [
Expand Down

0 comments on commit 43d805c

Please sign in to comment.