17
17
from django .db import transaction
18
18
19
19
from backend import env
20
- from backend .components import BKMonitorV3Api , CCApi
20
+ from backend .components import BKLogApi , BKMonitorV3Api , CCApi
21
21
from backend .configuration .models import BizSettings , DBAdministrator
22
22
from backend .db_meta .enums import ClusterType , ClusterTypeMachineTypeDefine
23
23
from backend .db_meta .models import AppMonitorTopo , Cluster , ClusterMonitorTopo , Machine , ProxyInstance , StorageInstance
24
- from backend .db_meta .models .cluster_monitor import INSTANCE_MONITOR_PLUGINS , SET_NAME_TEMPLATE
24
+ from backend .db_meta .models .cluster_monitor import INSTANCE_BKLOG_PLUGINS , INSTANCE_MONITOR_PLUGINS , SET_NAME_TEMPLATE
25
25
from backend .db_monitor .models import CollectInstance , MonitorPolicy
26
26
from backend .db_monitor .utils import create_bklog_collector
27
27
from backend .db_services .cmdb .biz import get_or_create_cmdb_module_with_name , get_or_create_set_with_name
@@ -581,12 +581,17 @@ def operate_collector(bk_biz_id: int, db_type: str, machine_type: str, bk_instan
581
581
if not bk_instance_ids :
582
582
return
583
583
584
- logger .error (
584
+ logger .info (
585
585
"operate_collector: {db_type} {machine_type} {bk_instance_ids} {action}" .format (
586
586
db_type = db_type , machine_type = machine_type , bk_instance_ids = bk_instance_ids , action = action
587
587
)
588
588
)
589
589
590
+ # 获取下发的实例和采集范围
591
+ nodes = [{"id" : bk_instance_id , "bk_biz_id" : bk_biz_id } for bk_instance_id in bk_instance_ids ]
592
+ scope = {"bk_biz_id" : bk_biz_id , "object_type" : "SERVICE" , "node_type" : "INSTANCE" , "nodes" : nodes }
593
+
594
+ # --- 下发监控采集器 ---
590
595
plugin_id = INSTANCE_MONITOR_PLUGINS [db_type ][machine_type ]["plugin_id" ]
591
596
collect_instances = CollectInstance .objects .filter (db_type = db_type , plugin_id = plugin_id )
592
597
for collect_ins in collect_instances :
@@ -595,22 +600,31 @@ def operate_collector(bk_biz_id: int, db_type: str, machine_type: str, bk_instan
595
600
continue
596
601
# 下发采集器
597
602
try :
598
- nodes = [{"id" : bk_instance_id , "bk_biz_id" : bk_biz_id } for bk_instance_id in bk_instance_ids ]
599
603
BKMonitorV3Api .run_collect_config (
600
- {
601
- "bk_biz_id" : env .DBA_APP_BK_BIZ_ID ,
602
- "id" : collect_ins .collect_id ,
603
- "scope" : {
604
- "bk_biz_id" : bk_biz_id ,
605
- "object_type" : "SERVICE" ,
606
- "node_type" : "INSTANCE" ,
607
- "nodes" : nodes ,
608
- },
609
- "action" : action ,
610
- }
604
+ {"bk_biz_id" : env .DBA_APP_BK_BIZ_ID , "id" : collect_ins .collect_id , "scope" : scope , "action" : action },
605
+ use_admin = True ,
611
606
)
612
607
except ApiError as err :
613
- logger .error (f"[run_collect_config] id:{ collect_ins .collect_id } error: { err } " )
608
+ logger .error (f"[monitor] id:{ collect_ins .collect_id } error: { err } " )
609
+
610
+ # --- 下发日志采集器 ---
611
+ plugin_id = INSTANCE_BKLOG_PLUGINS [db_type ][machine_type ]["plugin_id" ]
612
+ # 获取当前采集项的列表
613
+ data = BKLogApi .list_collectors ({"bk_biz_id" : env .DBA_APP_BK_BIZ_ID , "pagesize" : 500 , "page" : 1 }, use_admin = True )
614
+ collectors_name__info_map = {collector ["collector_config_name_en" ]: collector for collector in data ["list" ]}
615
+ collect = collectors_name__info_map .get (plugin_id )
616
+ # 忽略不存在的采集项
617
+ if not collect :
618
+ return
619
+ # 下发采集器
620
+ collect_id = collect ["collector_config_id" ]
621
+ try :
622
+ BKLogApi .run_databus_collectors (
623
+ {"bk_biz_id" : env .DBA_APP_BK_BIZ_ID , "collector_config_id" : collect_id , "scope" : scope , "action" : action },
624
+ use_admin = True ,
625
+ )
626
+ except ApiError as err :
627
+ logger .error (f"[bklog] id:{ collect_id } error: { err } " )
614
628
615
629
616
630
def trigger_operate_collector (
0 commit comments