增加审计日志、图表数据自动清理功能

This commit is contained in:
lanrenwo
2022-10-12 10:04:18 +08:00
parent 2c8474a478
commit 82dfb5d04f
13 changed files with 267 additions and 6 deletions

View File

@@ -203,7 +203,6 @@ func (s *StatsInfo) getScopeDetail(scope string) (sd *ScopeDetail) {
switch base.Cfg.DbType {
case "sqlite3", "postgres":
sd.fsTime = sd.sTime.UTC().Format(LayoutTimeFormat)
sd.feTime = sd.eTime.UTC().Format(LayoutTimeFormat)
}
return
}
@@ -237,3 +236,17 @@ func (s *StatsInfo) getStatsWhere(sd *ScopeDetail) (where string) {
}
return
}
func (s *StatsInfo) ClearStatsInfo(action string, ts string) (affected int64, err error) {
switch action {
case "online":
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsOnline{})
case "network":
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsNetwork{})
case "cpu":
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsCpu{})
case "mem":
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsMem{})
}
return affected, err
}