fix: ограничить статистику 7 днями и убрать 30d из дашборда

This commit is contained in:
2026-05-09 16:07:54 +05:00
parent 78656e74b0
commit 44c01d39d0
6 changed files with 62 additions and 22 deletions
+14 -3
View File
@@ -14,6 +14,7 @@ import (
)
const hysteriaVersionCacheTTL = 15 * time.Minute
const statsRetention = 7 * 24 * time.Hour
var ansiRe = regexp.MustCompile(`\x1b\[[0-9;]*[A-Za-z]`)
var hysteriaVersionRe = regexp.MustCompile(`(?i)v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?`)
@@ -150,9 +151,19 @@ func CollectMetricsSnapshot() {
_ = dao.SaveMetricSample(metric)
}
func CleanupMetricsRetention() {
cutoff := time.Now().Add(-72 * time.Hour).UnixMilli()
_ = dao.CleanupMetricSample(cutoff)
func CleanupStatsRetention() {
now := time.Now()
cutoffMs := now.Add(-statsRetention).UnixMilli()
hourMs := int64(time.Hour / time.Millisecond)
dayMs := int64(24 * time.Hour / time.Millisecond)
cutoffHour := cutoffMs - (cutoffMs % hourMs)
cutoffDay := cutoffMs - (cutoffMs % dayMs)
_ = dao.CleanupMetricSample(cutoffMs)
_ = dao.CleanupTrafficSample(cutoffMs)
_ = dao.CleanupTrafficAggregateHourly(cutoffHour)
_ = dao.CleanupTrafficAggregateDaily(cutoffDay)
}
func DashboardSnapshot() metricsSnapshot {