减少带宽统计显示的空档期

This commit is contained in:
GoEdgeLab
2022-09-05 16:04:34 +08:00
parent 088e414e7f
commit 746ac573ab
3 changed files with 18 additions and 19 deletions

View File

@@ -9,7 +9,6 @@ import (
"github.com/TeaOSLab/EdgeAPI/internal/goman"
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/types"
"sync"
@@ -20,10 +19,7 @@ var serverBandwidthStatsMap = map[string]*pb.ServerBandwidthStat{} // key => ban
var serverBandwidthStatsLocker = &sync.Mutex{}
func init() {
var ticker = time.NewTicker(5 * time.Minute)
if Tea.IsTesting() {
ticker = time.NewTicker(1 * time.Minute)
}
var ticker = time.NewTicker(1 * time.Minute)
dbs.OnReadyDone(func() {
goman.New(func() {

View File

@@ -415,11 +415,13 @@ func (this *ServerStatBoardService) ComposeServerStatBoard(ctx context.Context,
// 当前N分钟区间
{
// 查询最近的个时段,以尽可能获取数据
var minute1 = timeutil.FormatTime("Hi", time.Now().Unix()/300*300)
var minute2 = timeutil.FormatTime("Hi", time.Now().Unix()/300*300-300)
// 查询最近的个时段,以尽可能获取数据
var timestamp = time.Now().Unix() / 300 * 300
var minute1 = timeutil.FormatTime("Hi", timestamp)
var minute2 = timeutil.FormatTime("Hi", timestamp-300)
var minute3 = timeutil.FormatTime("Hi", timestamp-300*2)
for _, minute := range []string{minute1, minute2} {
for _, minute := range []string{minute1, minute2, minute3} {
bytes, err := models.SharedServerBandwidthStatDAO.FindMinutelyPeekBandwidthBytes(tx, req.ServerId, day, minute)
if err != nil {
return nil, err