mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-19 20:40:25 +08:00
服务看板增加峰值带宽数据
This commit is contained in:
@@ -409,6 +409,61 @@ func (this *ServerStatBoardService) ComposeServerStatBoard(ctx context.Context,
|
||||
var tx = this.NullTx()
|
||||
|
||||
// 带宽统计
|
||||
{
|
||||
var month = timeutil.Format("Ym")
|
||||
var day = timeutil.Format("Ymd")
|
||||
|
||||
// 当前N分钟区间
|
||||
{
|
||||
// 查询最近的两个时段,以尽可能获取数据
|
||||
var minute1 = timeutil.FormatTime("Hi", time.Now().Unix()/300*300)
|
||||
var minute2 = timeutil.FormatTime("Hi", time.Now().Unix()/300*300-300)
|
||||
|
||||
for _, minute := range []string{minute1, minute2} {
|
||||
bytes, err := models.SharedServerBandwidthStatDAO.FindMinutelyPeekBandwidthBytes(tx, req.ServerId, day, minute)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if bytes == 0 {
|
||||
// 尝试从缓存中读取
|
||||
bytes = ServerBandwidthGetCacheBytes(req.ServerId, day, minute)
|
||||
}
|
||||
|
||||
if bytes > 0 {
|
||||
result.MinutelyPeekBandwidthBytes = bytes
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当天
|
||||
{
|
||||
bytes, err := models.SharedServerBandwidthStatDAO.FindDailyPeekBandwidthBytes(tx, req.ServerId, day)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.DailyPeekBandwidthBytes = bytes
|
||||
}
|
||||
|
||||
// 当月
|
||||
{
|
||||
bytes, err := models.SharedServerBandwidthStatDAO.FindMonthlyPeekBandwidthBytes(tx, req.ServerId, month)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.MonthlyPeekBandwidthBytes = bytes
|
||||
}
|
||||
|
||||
// 上月
|
||||
{
|
||||
bytes, err := models.SharedServerBandwidthStatDAO.FindMonthlyPeekBandwidthBytes(tx, req.ServerId, timeutil.Format("Ym", time.Now().AddDate(0, -1, 0)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.LastMonthlyPeekBandwidthBytes = bytes
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var bandwidthMinutes = utils.RangeMinutes(time.Now(), 12, 5)
|
||||
var bandwidthStatMap = map[string]*pb.ServerBandwidthStat{}
|
||||
@@ -438,11 +493,11 @@ func (this *ServerStatBoardService) ComposeServerStatBoard(ctx context.Context,
|
||||
ServerId: req.ServerId,
|
||||
Day: minute.Day,
|
||||
TimeAt: minute.Minute,
|
||||
Bytes: 0,
|
||||
Bytes: ServerBandwidthGetCacheBytes(req.ServerId, minute.Day, minute.Minute), // 从当前缓存中读取
|
||||
})
|
||||
}
|
||||
}
|
||||
result.ServerBandwidthStats = pbBandwidthStats
|
||||
result.MinutelyBandwidthStats = pbBandwidthStats
|
||||
}
|
||||
|
||||
// 按日流量统计
|
||||
|
||||
Reference in New Issue
Block a user