mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-02-16 08:55:36 +08:00
重新实现套餐
This commit is contained in:
@@ -62,6 +62,7 @@ type BandwidthStat struct {
|
||||
CountRequests int64 `json:"countRequests"`
|
||||
CountCachedRequests int64 `json:"countCachedRequests"`
|
||||
CountAttackRequests int64 `json:"countAttackRequests"`
|
||||
UserPlanId int64 `json:"userPlanId"`
|
||||
}
|
||||
|
||||
// BandwidthStatManager 服务带宽统计
|
||||
@@ -153,6 +154,7 @@ func (this *BandwidthStatManager) Loop() error {
|
||||
CountRequests: stat.CountRequests,
|
||||
CountCachedRequests: stat.CountCachedRequests,
|
||||
CountAttackRequests: stat.CountAttackRequests,
|
||||
UserPlanId: stat.UserPlanId,
|
||||
NodeRegionId: regionId,
|
||||
})
|
||||
delete(this.m, key)
|
||||
@@ -178,7 +180,7 @@ func (this *BandwidthStatManager) Loop() error {
|
||||
}
|
||||
|
||||
// AddBandwidth 添加带宽数据
|
||||
func (this *BandwidthStatManager) AddBandwidth(userId int64, serverId int64, peekBytes int64, totalBytes int64) {
|
||||
func (this *BandwidthStatManager) AddBandwidth(userId int64, userPlanId int64, serverId int64, peekBytes int64, totalBytes int64) {
|
||||
if serverId <= 0 || (peekBytes == 0 && totalBytes == 0) {
|
||||
return
|
||||
}
|
||||
@@ -217,6 +219,7 @@ func (this *BandwidthStatManager) AddBandwidth(userId int64, serverId int64, pee
|
||||
Day: day,
|
||||
TimeAt: timeAt,
|
||||
UserId: userId,
|
||||
UserPlanId: userPlanId,
|
||||
ServerId: serverId,
|
||||
CurrentBytes: peekBytes,
|
||||
MaxBytes: peekBytes,
|
||||
|
||||
@@ -12,22 +12,22 @@ import (
|
||||
|
||||
func TestBandwidthStatManager_Add(t *testing.T) {
|
||||
var manager = stats.NewBandwidthStatManager()
|
||||
manager.AddBandwidth(1, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 0, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 0, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 0, 1, 10, 10)
|
||||
time.Sleep(1 * time.Second)
|
||||
manager.AddBandwidth(1, 1, 85, 85)
|
||||
manager.AddBandwidth(1, 0, 1, 85, 85)
|
||||
time.Sleep(1 * time.Second)
|
||||
manager.AddBandwidth(1, 1, 25, 25)
|
||||
manager.AddBandwidth(1, 1, 75, 75)
|
||||
manager.AddBandwidth(1, 0, 1, 25, 25)
|
||||
manager.AddBandwidth(1, 0, 1, 75, 75)
|
||||
manager.Inspect()
|
||||
}
|
||||
|
||||
func TestBandwidthStatManager_Loop(t *testing.T) {
|
||||
var manager = stats.NewBandwidthStatManager()
|
||||
manager.AddBandwidth(1, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 0, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 0, 1, 10, 10)
|
||||
manager.AddBandwidth(1, 0, 1, 10, 10)
|
||||
err := manager.Loop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -40,7 +40,7 @@ func BenchmarkBandwidthStatManager_Add(b *testing.B) {
|
||||
var i int
|
||||
for pb.Next() {
|
||||
i++
|
||||
manager.AddBandwidth(1, int64(i%100), 10, 10)
|
||||
manager.AddBandwidth(1, 0, int64(i%100), 10, 10)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user