snapshot: 数据源管理+大屏增强前快照
This commit is contained in:
1 parent
2bf3e7c308
commit
1726ad65ac
19 files changed
+2540
-273
No files matched your search
@@ -1,5 +1,6 @@
|
||||
// 主机监控 — Agent 采集指标展示 (CPU/内存/TCP/磁盘IO/趋势图) // Logan.Li
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { agentApi } from '@/services/api';
|
||||
import { useUserStore } from '@/store';
|
||||
import { asList, isOnline, timeAgo } from '@/components/agent/agentUtils';
|
||||
@@ -42,8 +43,10 @@ function fmtNum(n: number): string {
|
||||
}
|
||||
|
||||
export function HostMonitor() {
|
||||
const [searchParams] = useSearchParams();
|
||||
const urlHost = searchParams.get('host') || '';
|
||||
const [hosts, setHosts] = useState<any[]>([]);
|
||||
const [selectedHost, setSelectedHost] = useState('');
|
||||
const [selectedHost, setSelectedHost] = useState(urlHost);
|
||||
const [latest, setLatest] = useState<any>(null);
|
||||
const [cpuKlines, setCpuKlines] = useState<any[]>([]);
|
||||
const [memKlines, setMemKlines] = useState<any[]>([]);
|
||||
@@ -80,11 +83,13 @@ export function HostMonitor() {
|
||||
const list = asList(data);
|
||||
setHosts(list);
|
||||
if (list.length > 0 && !selectedHost) {
|
||||
setSelectedHost(list[0].hostname);
|
||||
// 优先匹配 URL 参数传入的主机
|
||||
const matched = urlHost ? list.find((h: any) => h.hostname === urlHost) : null;
|
||||
setSelectedHost(matched ? matched.hostname : list[0].hostname);
|
||||
}
|
||||
} catch { /* 后端不可用时显示空状态 */ }
|
||||
finally { setCardLoading(false); }
|
||||
}, [selectedHost]);
|
||||
}, [selectedHost, urlHost]);
|
||||
|
||||
useEffect(() => { loadHosts(); }, []);
|
||||
|
||||
|
||||
Reference in new issue
Block a user