新增实时监控模式,agent 1s 并行采集 + 前端滑动窗口
agent - 移除 collector.interval 配置项;按指标类型内置节奏:cpu/memory/network/ disk_io/gpu/network_connection 1s,temperature 5s,disk 30s,host 60s - doCollectAndSend 改为并行执行本 tick 到期的采集器,避免串行累计耗时 超过 1s 节奏;每个 goroutine 加 recover 兜底,单点 panic 不拖垮整 tick server - LatestMetrics 加 sync.RWMutex + Update/Snapshot 方法,HandleMetricData 所有写入走 Update;GetLatestMetrics 返回 Snapshot,handler 在副本上 sanitize,修复 marshal 时与 ws 写入的 data race(go test -race 验证) - HandleMetricData defer Set 缓存项,每次上报刷新 TTL;host case 也走 Update,不再 1 小时后失效 - LatestMetrics.Timestamp 用服务端 time.Now(),agent 时钟倒拨不会冻结 前端实时图;Timestamp/DiskIOSummary 字段补到 LatestMetrics - AutoStep 新增 r ≤ 5m → 1s 档;timeRangeMilliseconds 加 2m frontend - 详情页加"实时"档位(默认),1s 拉 latestMetrics + 1m 历史播种 + 滑动 2 分钟窗口;快图表(CPU/Memory/Network/DiskIO/NetworkConnection)走 useLiveBuffer 追加,慢图表(GPU/Temperature/Monitor)保留 refetch - useLiveBuffer:seed 不再覆盖已追加的 livePoint;resetKey 处理切网卡 / 切 agent 时的语义复位 - formatChartTime live 档位精确到秒;修复 1d/24h 仅显示 HH:mm 跨夜歧义 - 慢图表用 React.memo,阻断 1Hz 节奏的级联重渲染 - GpuChart 修复 utilization/temperature 时间戳错位时温度点丢失 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e115d828ab
commit
c431f300bc
25 files changed
+655
-217
No files matched your search
@@ -17,6 +17,7 @@ var validMetricTypes = map[string]struct{}{
|
||||
|
||||
var timeRangeMilliseconds = map[string]int64{
|
||||
"1m": int64(time.Minute / time.Millisecond),
|
||||
"2m": int64(2 * time.Minute / time.Millisecond),
|
||||
"5m": int64(5 * time.Minute / time.Millisecond),
|
||||
"15m": int64(15 * time.Minute / time.Millisecond),
|
||||
"30m": int64(30 * time.Minute / time.Millisecond),
|
||||
@@ -41,7 +42,7 @@ func parseTimeRange(rangeParam string) (start, end int64, err error) {
|
||||
|
||||
durationMs, ok := timeRangeMilliseconds[rangeParam]
|
||||
if !ok {
|
||||
return 0, 0, fmt.Errorf("无效的时间范围,支持: 1m, 5m, 15m, 30m, 1h, 3h, 6h, 12h, 1d/24h, 3d, 7d, 30d")
|
||||
return 0, 0, fmt.Errorf("无效的时间范围,支持: 1m, 2m, 5m, 15m, 30m, 1h, 3h, 6h, 12h, 1d/24h, 3d, 7d, 30d")
|
||||
}
|
||||
start = end - durationMs
|
||||
|
||||
@@ -147,12 +148,10 @@ func (h *AgentHandler) GetLatestMetrics(c echo.Context) error {
|
||||
if !ok {
|
||||
return orz.NewError(404, "探针最新指标不存在")
|
||||
}
|
||||
// metrics 已经是独立 snapshot,未登录时直接在副本上抹掉敏感字段即可
|
||||
if !isAuthenticated {
|
||||
sanitized := *metrics
|
||||
sanitized.NetworkInterfaces = nil
|
||||
return orz.Ok(c, &sanitized)
|
||||
metrics.NetworkInterfaces = nil
|
||||
}
|
||||
|
||||
return orz.Ok(c, metrics)
|
||||
}
|
||||
|
||||
|
||||
@@ -82,14 +82,11 @@ func (h *AgentHandler) buildAgentListItem(agent models.Agent, isAuthenticated bo
|
||||
}
|
||||
|
||||
metrics, ok := h.metricService.GetLatestMetrics(agent.ID)
|
||||
if ok {
|
||||
if !isAuthenticated && metrics != nil {
|
||||
sanitized := *metrics
|
||||
sanitized.NetworkInterfaces = nil
|
||||
item["metrics"] = &sanitized
|
||||
} else {
|
||||
item["metrics"] = metrics
|
||||
if ok && metrics != nil {
|
||||
if !isAuthenticated {
|
||||
metrics.NetworkInterfaces = nil
|
||||
}
|
||||
item["metrics"] = metrics
|
||||
}
|
||||
|
||||
return item
|
||||
|
||||
Reference in new issue
Block a user