优化 local 模式兼容性与部署可靠性
- SQL 方言层:agent updated_at、dashboard 小时分桶、清理任务跨 SQLite/MySQL - Cache Capabilities:redka 跳过 ZSet/PubSub,Agent 聚合改 DB 直读 - local 模式 redka 初始化失败 Fatal;/version 返回 features - SQLite WAL + 连接池限制;K8s data 改 PVC 持久化 - run.sh:旧参数迁移、升级后 /version 校验
This commit is contained in:
1 parent
1f4f63cf6e
commit
b7166acda4
13 files changed
+374
-152
No files matched your search
+20
-9
@@ -139,10 +139,21 @@ func main() {
|
||||
DataDir: "data/redka",
|
||||
})
|
||||
if err != nil {
|
||||
if cfg.Mode == "local" {
|
||||
log.Fatal("local 模式缓存(redka)初始化失败", zap.Error(err))
|
||||
}
|
||||
log.Warn("缓存初始化失败,继续启动", zap.Error(err))
|
||||
cache = nil
|
||||
} else {
|
||||
log.Info("缓存已就绪", zap.String("driver", cfg.Redis.Driver))
|
||||
caps := cache.Capabilities()
|
||||
log.Info("缓存已就绪",
|
||||
zap.String("driver", cfg.Redis.Driver),
|
||||
zap.Bool("sorted_set", caps.SortedSet),
|
||||
zap.Bool("pubsub", caps.PubSub),
|
||||
)
|
||||
if cfg.Mode == "local" && (!caps.SortedSet || !caps.PubSub) {
|
||||
log.Info("local 模式:Agent 热指标走 DB 直读,流水线日志走轮询")
|
||||
}
|
||||
defer cache.Close()
|
||||
}
|
||||
|
||||
@@ -156,14 +167,18 @@ func main() {
|
||||
|
||||
// 版本信息 API
|
||||
r.GET("/version", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
resp := gin.H{
|
||||
"version": Version,
|
||||
"build_time": BuildTime,
|
||||
"git_commit": GitCommit,
|
||||
"mode": cfg.Mode,
|
||||
"db_driver": cfg.Database.Driver,
|
||||
"redis_driver": cfg.Redis.Driver,
|
||||
})
|
||||
}
|
||||
if cache != nil {
|
||||
resp["features"] = cache.Capabilities()
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
})
|
||||
|
||||
// 注册路由
|
||||
@@ -173,13 +188,9 @@ func main() {
|
||||
go func() {
|
||||
ticker := time.NewTicker(24 * time.Hour)
|
||||
defer ticker.Stop()
|
||||
cleanupSQL := database.CleanupAgentReportsSQL(cfg.Database.Driver)
|
||||
for range ticker.C {
|
||||
var rows int64
|
||||
if cfg.Database.Driver == "sqlite" {
|
||||
rows = db.Exec("DELETE FROM monitor_agent_reports WHERE report_time < datetime('now', '-7 days')").RowsAffected
|
||||
} else {
|
||||
rows = db.Exec("DELETE FROM monitor_agent_reports WHERE report_time < DATE_SUB(NOW(), INTERVAL 7 DAY)").RowsAffected
|
||||
}
|
||||
rows := db.Exec(cleanupSQL).RowsAffected
|
||||
if rows > 0 {
|
||||
log.Info("清理过期的 agent 上报数据", zap.Int64("rows", rows))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user