优化 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
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"ezops/model"
|
||||
"ezops/pkg/database"
|
||||
ezredis "ezops/pkg/redis"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -39,16 +40,18 @@ func (h *DashboardHandler) GetStats(c *gin.Context) {
|
||||
const cacheKey = "dashboard:stats"
|
||||
const cacheTTL = 30 * time.Second
|
||||
|
||||
// 尝试从 Redis 缓存读取
|
||||
if cached, err := h.cache.Get(c.Request.Context(), cacheKey); err == nil && cached != "" {
|
||||
var stats model.DashboardStats
|
||||
if json.Unmarshal([]byte(cached), &stats) == nil {
|
||||
c.JSON(http.StatusOK, model.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: stats,
|
||||
})
|
||||
return
|
||||
// 尝试从缓存读取
|
||||
if h.cache != nil {
|
||||
if cached, err := h.cache.Get(c.Request.Context(), cacheKey); err == nil && cached != "" {
|
||||
var stats model.DashboardStats
|
||||
if json.Unmarshal([]byte(cached), &stats) == nil {
|
||||
c.JSON(http.StatusOK, model.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: stats,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,9 +234,11 @@ func (h *DashboardHandler) GetStats(c *gin.Context) {
|
||||
}
|
||||
stats.ExpiringCerts = expiringCerts
|
||||
|
||||
// 写入 Redis 缓存(异步,缓存失败不影响响应)
|
||||
if data, err := json.Marshal(stats); err == nil {
|
||||
_ = h.cache.Set(context.Background(), cacheKey, string(data), cacheTTL)
|
||||
// 写入缓存(异步,缓存失败不影响响应)// Logan.Li
|
||||
if h.cache != nil {
|
||||
if data, err := json.Marshal(stats); err == nil {
|
||||
_ = h.cache.Set(context.Background(), cacheKey, string(data), cacheTTL)
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.Response{
|
||||
@@ -327,8 +332,9 @@ func (h *DashboardHandler) GetMetrics(c *gin.Context) {
|
||||
AvgMem float64
|
||||
}
|
||||
var rows []avgPoint
|
||||
bucketExpr := database.HourBucketExpr(database.DriverName(h.db))
|
||||
h.db.Model(&model.AgentReport{}).
|
||||
Select("UNIX_TIMESTAMP(report_time) DIV 3600 as bucket_ts, ROUND(AVG(cpu_usage),2) as avg_cpu, ROUND(AVG(mem_usage),2) as avg_mem").
|
||||
Select(fmt.Sprintf("%s as bucket_ts, ROUND(AVG(cpu_usage),2) as avg_cpu, ROUND(AVG(mem_usage),2) as avg_mem", bucketExpr)).
|
||||
Where("report_time >= ?", since).
|
||||
Group("bucket_ts").
|
||||
Order("bucket_ts ASC").
|
||||
|
||||
Reference in new issue
Block a user