diff --git a/README.md b/README.md index 618ec9e..693daf8 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ ### 通知 - +正在开发,进度 0% ## 常见问题 diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 430c791..4f20562 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -40,7 +40,6 @@ var ( ) var ( - endReport time.Time reporting bool client pb.NezhaServiceClient ctx = context.Background() @@ -97,13 +96,14 @@ func run(cmd *cobra.Command, args []string) { // 上报服务器信息 go reportState() - go func() { - for range updateCh { - go doSelfUpdate() - } - }() - - updateCh <- struct{}{} + if version != "" { + go func() { + for range updateCh { + go doSelfUpdate() + } + }() + updateCh <- struct{}{} + } var err error var conn *grpc.ClientConn @@ -161,8 +161,6 @@ func receiveCommand(hc pb.NezhaService_HeartbeatClient) error { return err } switch action.GetType() { - case model.MTReportState: - endReport = time.Now().Add(time.Minute * 10) default: log.Printf("Unknown action: %v", action) } @@ -171,17 +169,15 @@ func receiveCommand(hc pb.NezhaService_HeartbeatClient) error { func reportState() { var err error - defer log.Printf("reportState exit %v %v => %v", endReport, time.Now(), err) + defer log.Printf("reportState exit %v => %v", time.Now(), err) for { - if endReport.After(time.Now()) { + if client != nil { monitor.TrackNetworkSpeed() _, err = client.ReportState(ctx, monitor.GetState(2).PB()) if err != nil { log.Printf("reportState error %v", err) time.Sleep(delayWhenError) } - } else { - time.Sleep(time.Second * 1) } } } diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go index f391c5a..a2ee62e 100644 --- a/cmd/dashboard/controller/common_page.go +++ b/cmd/dashboard/controller/common_page.go @@ -2,7 +2,6 @@ package controller import ( "net/http" - "sync" "time" "github.com/gin-gonic/gin" @@ -10,7 +9,6 @@ import ( "github.com/naiba/nezha/model" "github.com/naiba/nezha/pkg/mygin" - pb "github.com/naiba/nezha/proto" "github.com/naiba/nezha/service/dao" ) @@ -54,35 +52,13 @@ func (cp *commonPage) ws(c *gin.Context) { return } defer conn.Close() - var wg sync.WaitGroup - wg.Add(2) - go func() { - var mt int - var message []byte - for { - mt, message, err = conn.ReadMessage() - if err != nil { - wg.Done() - break - } - if mt == websocket.TextMessage && string(message) == "track" { - dao.SendCommand(&pb.Command{ - Type: model.MTReportState, - }) - } + for { + dao.ServerLock.RLock() + err = conn.WriteJSON(dao.ServerList) + dao.ServerLock.RUnlock() + if err != nil { + break } - }() - go func() { - for { - dao.ServerLock.RLock() - err = conn.WriteJSON(dao.ServerList) - dao.ServerLock.RUnlock() - if err != nil { - wg.Done() - break - } - time.Sleep(time.Second * 2) - } - }() - wg.Wait() + time.Sleep(time.Second * 2) + } } diff --git a/resource/template/common/header.html b/resource/template/common/header.html index 598bbc7..fdeba43 100644 --- a/resource/template/common/header.html +++ b/resource/template/common/header.html @@ -9,7 +9,7 @@