diff --git a/backend/controller/agent.go b/backend/controller/agent.go index 40a114e..4cfed01 100644 --- a/backend/controller/agent.go +++ b/backend/controller/agent.go @@ -277,7 +277,7 @@ func (h *AgentHandler) writeHotMetric(c *gin.Context, key string, value float64, // GET /api/v1/agent/latest func (h *AgentHandler) GetLatestReports(c *gin.Context) { var results []model.AgentLatestResponse - threeMinAgo := time.Now().Add(-3 * time.Minute) + threeMinAgo := time.Now().UTC().Add(-3 * time.Minute) // SQLite 上报时间统一以 UTC 持久化。 // Logan.Li // 以 servers 表为主,按资产名或 Agent 自报 IP 关联最近 3 分钟内的上报。 // Logan.Li // 未装 Agent 的主机也会显示(agent_status='not_installed'),打破"不显示→无法安装"的循环 h.db.Raw(` @@ -348,7 +348,7 @@ func parseFlexibleTime(s string) (time.Time, error) { } for _, layout := range layouts { if t, err := time.ParseInLocation(layout, s, time.Local); err == nil { - return t, nil + return t.UTC(), nil // 历史报告使用 UTC 存储,避免自定义时间范围跨时区漏数。 // Logan.Li } } return time.Time{}, fmt.Errorf("无法解析时间: %s", s) @@ -356,7 +356,7 @@ func parseFlexibleTime(s string) (time.Time, error) { // resolveHostHistoryRange 解析历史查询时间范围(minutes / hours / start+end) // Logan.Li func resolveHostHistoryRange(c *gin.Context) (since, until time.Time, err error) { - until = time.Now() + until = time.Now().UTC() // 历史报告使用 UTC 存储,避免本地时区造成范围比较失效。 // Logan.Li if startStr := strings.TrimSpace(c.Query("start")); startStr != "" { endStr := strings.TrimSpace(c.Query("end")) if endStr == "" {