Merge pull request #37 from CHENPrime-coder/fix/all_metrics_503
refactor: 把status页面的agent-metrics拆分成一个个独立的请求
This commit is contained in:
2 files changed
+11
-11
No files matched your search
@@ -240,23 +240,13 @@ export async function getStatusPagePublicData(env: { DB: Bindings["DB"] }) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取客户端详细信息
|
||||
// 获取客户端基本信息
|
||||
let agents: Agent[] = [];
|
||||
if (selectedAgents.results && selectedAgents.results.length > 0) {
|
||||
const agentIds = selectedAgents.results.map((a) => a.agent_id);
|
||||
|
||||
if (agentIds.length > 0) {
|
||||
const agentsResult = await repositories.getAgentsByIds(env.DB, agentIds);
|
||||
const agentsMetricsResult =
|
||||
await repositories.getAgentMetricsByIds(env.DB, agentIds);
|
||||
if (agentsMetricsResult.results) {
|
||||
for (const agent of agentsResult.results || []) {
|
||||
const agentMetrics = agentsMetricsResult.results.filter(
|
||||
(m) => m.agent_id === agent.id
|
||||
);
|
||||
agent.metrics = agentMetrics;
|
||||
}
|
||||
}
|
||||
|
||||
if (agentsResult.results) {
|
||||
agents = agentsResult.results;
|
||||
|
||||
@@ -5,6 +5,7 @@ import AgentCard from "../../components/AgentCard";
|
||||
import MonitorCard from "../../components/MonitorCard";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Agent, MonitorWithDailyStatsAndStatusHistory } from "../../types";
|
||||
import { getAgentMetrics } from "../../api";
|
||||
|
||||
const StatusPage = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -47,6 +48,15 @@ const StatusPage = () => {
|
||||
setPageDescription(
|
||||
response.description || t("statusPage.allOperational")
|
||||
);
|
||||
if (response.agents) {
|
||||
// 获取每个代理的指标数据
|
||||
await Promise.all(
|
||||
response.agents.map(async (agent) => {
|
||||
const metrics = await getAgentMetrics(agent.id);
|
||||
agent.metrics = metrics.agent || [];
|
||||
})
|
||||
);
|
||||
}
|
||||
console.log(response);
|
||||
setData({
|
||||
monitors: response.monitors || [],
|
||||
|
||||
Reference in new issue
Block a user