From accd0236ea0792f2233244b6b89f9d1fbb71d98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 19 Apr 2023 22:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=9F=E8=AE=A1=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/stats/http_request_stat_manager.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/stats/http_request_stat_manager.go b/internal/stats/http_request_stat_manager.go index 8a6af70..3982f71 100644 --- a/internal/stats/http_request_stat_manager.go +++ b/internal/stats/http_request_stat_manager.go @@ -54,6 +54,9 @@ type HTTPRequestStatManager struct { totalAttackRequests int64 locker sync.Mutex + + monitorTicker *time.Ticker + uploadTicker *time.Ticker } // NewHTTPRequestStatManager 获取新对象 @@ -77,12 +80,12 @@ func NewHTTPRequestStatManager() *HTTPRequestStatManager { // Start 启动 func (this *HTTPRequestStatManager) Start() { // 上传请求总数 - var monitorTicker = time.NewTicker(1 * time.Minute) + this.monitorTicker = time.NewTicker(1 * time.Minute) events.OnKey(events.EventQuit, this, func() { - monitorTicker.Stop() + this.monitorTicker.Stop() }) goman.New(func() { - for range monitorTicker.C { + for range this.monitorTicker.C { if this.totalAttackRequests > 0 { monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemAttackRequests, maps.Map{"total": this.totalAttackRequests}) this.totalAttackRequests = 0 @@ -90,19 +93,19 @@ func (this *HTTPRequestStatManager) Start() { } }) - var uploadTicker = time.NewTicker(30 * time.Minute) + this.uploadTicker = time.NewTicker(30 * time.Minute) if Tea.IsTesting() { - uploadTicker = time.NewTicker(10 * time.Second) // 在测试环境下缩短Ticker时间,以方便我们调试 + this.uploadTicker = time.NewTicker(10 * time.Second) // 在测试环境下缩短Ticker时间,以方便我们调试 } remotelogs.Println("HTTP_REQUEST_STAT_MANAGER", "start ...") events.OnKey(events.EventQuit, this, func() { remotelogs.Println("HTTP_REQUEST_STAT_MANAGER", "quit") - uploadTicker.Stop() + this.uploadTicker.Stop() }) // 上传Ticker goman.New(func() { - for range uploadTicker.C { + for range this.uploadTicker.C { var tr = trackers.Begin("UPLOAD_REQUEST_STATS") err := this.Upload() tr.End() @@ -378,7 +381,7 @@ func (this *HTTPRequestStatManager) Upload() error { sort.Slice(pbCities, func(i, j int) bool { return pbCities[i].CountRequests > pbCities[j].CountRequests }) - var serverCountMap = map[int64]int16{} + var serverCountMap = map[int64]int16{} // serverId => count for _, city := range pbCities { serverCountMap[city.ServerId]++ if serverCountMap[city.ServerId] > maxCities {