mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 10:00:24 +08:00
服务看板增加区域地图
This commit is contained in:
@@ -145,6 +145,22 @@ func (this *ServerRegionCountryDailyStatDAO) SumDailyTotalAttackRequests(tx *dbs
|
||||
SumInt64("countAttackRequests", 0)
|
||||
}
|
||||
|
||||
// SumDailyTotalBytesWithServerId 计算单个服务的总流量
|
||||
func (this *ServerRegionCountryDailyStatDAO) SumDailyTotalBytesWithServerId(tx *dbs.Tx, day string, serverId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Attr("day", day).
|
||||
Attr("serverId", serverId).
|
||||
SumInt64("bytes", 0)
|
||||
}
|
||||
|
||||
// SumDailyTotalAttackRequestsWithServerId 计算单个服务的总攻击次数
|
||||
func (this *ServerRegionCountryDailyStatDAO) SumDailyTotalAttackRequestsWithServerId(tx *dbs.Tx, day string, serverId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Attr("day", day).
|
||||
Attr("serverId", serverId).
|
||||
SumInt64("countAttackRequests", 0)
|
||||
}
|
||||
|
||||
// Clean 清理统计数据
|
||||
func (this *ServerRegionCountryDailyStatDAO) Clean(tx *dbs.Tx) error {
|
||||
// 只保留7天的
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
@@ -514,6 +515,34 @@ func (this *ServerStatBoardService) ComposeServerStatBoard(ctx context.Context,
|
||||
})
|
||||
}
|
||||
|
||||
// 地区流量排行
|
||||
totalCountryBytes, err := stats.SharedServerRegionCountryDailyStatDAO.SumDailyTotalBytesWithServerId(tx, timeutil.Format("Ymd"), req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if totalCountryBytes > 0 {
|
||||
topCountryStats, err := stats.SharedServerRegionCountryDailyStatDAO.ListServerStats(tx, req.ServerId, timeutil.Format("Ymd"), "bytes", 0, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, stat := range topCountryStats {
|
||||
countryName, err := regions.SharedRegionCountryDAO.FindRegionCountryName(tx, int64(stat.CountryId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.TopCountryStats = append(result.TopCountryStats, &pb.ComposeServerStatBoardResponse_CountryStat{
|
||||
CountryName: countryName,
|
||||
Bytes: int64(stat.Bytes),
|
||||
CountRequests: int64(stat.CountRequests),
|
||||
AttackBytes: int64(stat.AttackBytes),
|
||||
CountAttackRequests: int64(stat.CountAttackRequests),
|
||||
Percent: float32(stat.Bytes*100) / float32(totalCountryBytes),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 指标
|
||||
clusterId, err := models.SharedServerDAO.FindServerClusterId(tx, req.ServerId)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user