fix
This commit is contained in:
@@ -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 () => {
|
const getAllMetrics = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -472,8 +485,9 @@ const getAllMetrics = async () => {
|
|||||||
let metricsUrl = record.agent_config
|
let metricsUrl = record.agent_config
|
||||||
|
|
||||||
// 验证 URL 是否合法
|
// 验证 URL 是否合法
|
||||||
|
let agentUrl: URL
|
||||||
try {
|
try {
|
||||||
new URL(metricsUrl)
|
agentUrl = new URL(metricsUrl)
|
||||||
} catch (urlError) {
|
} catch (urlError) {
|
||||||
console.warn(`服务器 ${record.name} 的 agent_config 不是合法的 URL:`, metricsUrl)
|
console.warn(`服务器 ${record.name} 的 agent_config 不是合法的 URL:`, metricsUrl)
|
||||||
// 设置默认值 0
|
// 设置默认值 0
|
||||||
@@ -482,8 +496,12 @@ const getAllMetrics = async () => {
|
|||||||
record.disk_info = { value: 0, total: '', used: '' }
|
record.disk_info = { value: 0, total: '', used: '' }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// dc-host 控制面拉取指标接口为 POST
|
||||||
|
const isDcHostCommand = agentUrl.pathname.includes('/dc-host/v1/control/command')
|
||||||
// 使用独立的 axios 实例请求外部 agent,绕过全局拦截器
|
// 使用独立的 axios 实例请求外部 agent,绕过全局拦截器
|
||||||
const response = await agentAxios.get(metricsUrl)
|
const response = isDcHostCommand
|
||||||
|
? await agentAxios.post(metricsUrl, buildDcHostServiceCollectBody())
|
||||||
|
: await agentAxios.get(metricsUrl)
|
||||||
console.log('获取指标数据:', response.data)
|
console.log('获取指标数据:', response.data)
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
// 更新记录的监控数据
|
// 更新记录的监控数据
|
||||||
|
|||||||
Reference in New Issue
Block a user