This commit is contained in:
zxr
2026-04-12 15:01:46 +08:00
parent 5f4111aeb1
commit 1dcab7af96

View File

@@ -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) {
// 更新记录的监控数据