diff --git a/src/views/ops/pages/dc/server/index.vue b/src/views/ops/pages/dc/server/index.vue index c4707f9..c0e2726 100644 --- a/src/views/ops/pages/dc/server/index.vue +++ b/src/views/ops/pages/dc/server/index.vue @@ -460,6 +460,19 @@ const handleDelete = async (record: any) => { }) } +/** dc-host `/dc-host/v1/control/command` 拉取本机采集指标(execute_task + service_collect) */ +const buildDcHostServiceCollectBody = () => ({ + command: 'execute_task' as const, + params: { + task_id: 0, + task_name: 'service_collect', + type: 'host' as const, + config: '{}', + timeout: 120, + }, + timestamp: new Date().toISOString(), +}) + // 获取所有服务器的监控指标 const getAllMetrics = async () => { try { @@ -472,8 +485,9 @@ const getAllMetrics = async () => { let metricsUrl = record.agent_config // 验证 URL 是否合法 + let agentUrl: URL try { - new URL(metricsUrl) + agentUrl = new URL(metricsUrl) } catch (urlError) { console.warn(`服务器 ${record.name} 的 agent_config 不是合法的 URL:`, metricsUrl) // 设置默认值 0 @@ -482,8 +496,12 @@ const getAllMetrics = async () => { record.disk_info = { value: 0, total: '', used: '' } return } + // dc-host 控制面拉取指标接口为 POST + const isDcHostCommand = agentUrl.pathname.includes('/dc-host/v1/control/command') // 使用独立的 axios 实例请求外部 agent,绕过全局拦截器 - const response = await agentAxios.get(metricsUrl) + const response = isDcHostCommand + ? await agentAxios.post(metricsUrl, buildDcHostServiceCollectBody()) + : await agentAxios.get(metricsUrl) console.log('获取指标数据:', response.data) if (response.data) { // 更新记录的监控数据