fix: полный продакшен-фикс dashboard retention и timeseries по fix37

This commit is contained in:
2026-05-09 16:18:08 +05:00
parent 44c01d39d0
commit b6c86009e6
6 changed files with 35 additions and 33 deletions
+15 -10
View File
@@ -83,8 +83,8 @@ func DashboardTrafficSummary() (vo.DashboardTrafficVo, error) {
result.SinceResetDownloadBytes = r.Download
result.SinceResetUploadBytes = r.Upload
now := time.Now().UnixMilli()
dayStart := now - (now % int64(24*time.Hour/time.Millisecond))
nowTime := time.Now()
dayStart := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, nowTime.Location()).UnixMilli()
var today row
if tx := sqliteDB.Raw(`SELECT
COALESCE(SUM(rx_bytes),0) AS download,
@@ -135,9 +135,6 @@ func DashboardTrafficTimeseries(fromMs int64, toMs int64, bucketMs int64, source
case "hourly":
sourceTable = "traffic_aggregate_hourly"
fromColumn = "hour_start"
case "daily":
sourceTable = "traffic_aggregate_daily"
fromColumn = "day_start"
default:
sourceTable = "traffic_sample"
fromColumn = "sampled_at"
@@ -171,18 +168,26 @@ func DashboardTrafficTimeseries(fromMs int64, toMs int64, bucketMs int64, source
return filled, nil
}
func DashboardSystemTimeseries(fromMs int64, toMs int64) ([]vo.DashboardSeriesPointVo, error) {
func DashboardSystemTimeseries(fromMs int64, toMs int64, bucketMs int64) ([]vo.DashboardSeriesPointVo, error) {
rows := make([]vo.DashboardSeriesPointVo, 0)
if !tableExists("metric_sample") {
return rows, nil
}
if toMs < fromMs {
return rows, nil
}
if bucketMs <= 0 {
bucketMs = int64(time.Minute / time.Millisecond)
}
alignedFrom := fromMs - (fromMs % bucketMs)
if tx := sqliteDB.Raw(`SELECT
sampled_at AS ts,
cpu_percent AS cpu,
mem_percent AS mem
(? + CAST((sampled_at - ?) / ? AS INTEGER) * ?) AS ts,
AVG(cpu_percent) AS cpu,
AVG(mem_percent) AS mem
FROM metric_sample
WHERE sampled_at BETWEEN ? AND ?
ORDER BY sampled_at ASC`, fromMs, toMs).Scan(&rows); tx.Error != nil {
GROUP BY ts
ORDER BY ts ASC`, alignedFrom, alignedFrom, bucketMs, bucketMs, fromMs, toMs).Scan(&rows); tx.Error != nil {
logrus.Errorf("%v", tx.Error)
return rows, errors.New(constant.SysError)
}