perf: dashboard 默认6小时查询(减73%扫描行) + 7天自动清理 + 5分钟自动刷新
This commit is contained in:
1 parent
20f64e3851
commit
bc813e611c
2 files changed
+16
-1
No files matched your search
@@ -164,6 +164,18 @@ func main() {
|
|||||||
// 注册路由
|
// 注册路由
|
||||||
routes.Register(r, db, log, cfg, cache)
|
routes.Register(r, db, log, cfg, cache)
|
||||||
|
|
||||||
|
// 定期清理旧的 agent 上报数据(保留 7 天,防止表膨胀影响查询性能)
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(24 * time.Hour)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for range ticker.C {
|
||||||
|
result := db.Exec("DELETE FROM monitor_agent_reports WHERE report_time < DATE_SUB(NOW(), INTERVAL 7 DAY)")
|
||||||
|
if result.RowsAffected > 0 {
|
||||||
|
log.Info("清理过期的 agent 上报数据", zap.Int64("rows", result.RowsAffected))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// 前端静态文件服务(go:embed 模式,二进制部署用) // Logan.Li
|
// 前端静态文件服务(go:embed 模式,二进制部署用) // Logan.Li
|
||||||
setupFrontend(r)
|
setupFrontend(r)
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export function Dashboard() {
|
|||||||
console.error('Failed to fetch dashboard releases:', e);
|
console.error('Failed to fetch dashboard releases:', e);
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
dashboardStatsApi.getMetrics(24).catch((e) => {
|
dashboardStatsApi.getMetrics(6).catch((e) => {
|
||||||
console.error('Failed to fetch metrics:', e);
|
console.error('Failed to fetch metrics:', e);
|
||||||
return [];
|
return [];
|
||||||
}),
|
}),
|
||||||
@@ -85,6 +85,9 @@ export function Dashboard() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshData();
|
refreshData();
|
||||||
|
// 每 5 分钟自动刷新
|
||||||
|
const interval = setInterval(refreshData, 5 * 60 * 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
}, [refreshData]);
|
}, [refreshData]);
|
||||||
|
|
||||||
if (initialLoading) {
|
if (initialLoading) {
|
||||||
|
|||||||
Reference in new issue
Block a user