优化数据统计

This commit is contained in:
刘祥超
2023-07-30 14:49:16 +08:00
parent eb145393ab
commit 45c6b2ddac
8 changed files with 61 additions and 8 deletions
+2 -1
View File
@@ -132,9 +132,10 @@ func (this *BandwidthStatManager) Loop() error {
for key, stat := range this.m {
if stat.Day < day || stat.TimeAt < currentTime {
// 防止数据出现错误
if stat.CachedBytes > stat.TotalBytes {
if stat.CachedBytes > stat.TotalBytes || stat.CountCachedRequests == stat.CountRequests {
stat.CachedBytes = stat.TotalBytes
}
if stat.AttackBytes > stat.TotalBytes {
stat.AttackBytes = stat.TotalBytes
}
+6 -2
View File
@@ -42,8 +42,6 @@ func (this *TrafficItem) Add(anotherItem *TrafficItem) {
this.AttackBytes += anotherItem.AttackBytes
}
const trafficStatsMaxLife = 1200 // 最大只保存20分钟内的数据
// TrafficStatManager 区域流量统计
type TrafficStatManager struct {
itemMap map[string]*TrafficItem // [timestamp serverId] => *TrafficItem
@@ -231,6 +229,12 @@ func (this *TrafficStatManager) Upload() error {
if len(pieces) != 2 {
continue
}
// 修正数据
if item.CachedBytes > item.Bytes || item.CountCachedRequests == item.CountRequests {
item.CachedBytes = item.Bytes
}
var pbItem = &pb.UploadServerDailyStatsRequest_DomainStat{
ServerId: serverId,
Domain: pieces[1],