@@ -26,7 +26,7 @@ import {
26
26
import {
27
27
getAllAgents ,
28
28
deleteAgent ,
29
- getAllAgentMetrics ,
29
+ getAgentMetrics ,
30
30
} from "../../api/agents" ;
31
31
import AgentCard from "../../components/AgentCard" ;
32
32
import { useTranslation } from "react-i18next" ;
@@ -68,19 +68,23 @@ const AgentsList = () => {
68
68
setError ( null ) ;
69
69
// 获取所有客户端
70
70
const response = await getAllAgents ( ) ;
71
- // 获取所有客户端的指标数据
72
- const metricsResponse = await getAllAgentMetrics ( ) ;
73
71
74
- if ( response . agents && metricsResponse . metrics ) {
72
+ if ( response . agents ) {
75
73
// 合并指标数据到客户端数据
76
- const agentsWithMetrics = response . agents . map ( ( agent ) => {
77
- const metrics = metricsResponse . metrics ?. filter (
78
- ( metric ) => metric . agent_id === agent . id
79
- ) ;
80
- console . log ( "获取到的 metrics 数据: " , metrics ) ;
81
- console . log ( "获取到的 agent 数据: " , agent ) ;
82
- return { ...agent , metrics } ;
83
- } ) ;
74
+ const agentsWithMetrics = await Promise . all (
75
+ response . agents . map ( async ( agent ) => {
76
+ // 获取指定客户端的指标数据
77
+ const metricsResponse = await getAgentMetrics ( agent . id ) ;
78
+ if ( ! metricsResponse . success ) {
79
+ console . error ( "获取指标数据失败:" , metricsResponse . message ) ;
80
+ return agent ; // 返回原始客户端数据
81
+ }
82
+ const metrics = metricsResponse . agent ;
83
+ console . log ( "获取到的 metrics 数据: " , metrics ) ;
84
+ console . log ( "获取到的 agent 数据: " , agent ) ;
85
+ return { ...agent , metrics } ;
86
+ } )
87
+ ) ;
84
88
setAgents ( agentsWithMetrics ) ;
85
89
}
86
90
console . log ( "获取到的 agent 数据: " , response ) ;
0 commit comments