From 6a70e67ef91fb5074553ed1bcc02557025d18455 Mon Sep 17 00:00:00 2001 From: naiba Date: Fri, 2 Aug 2024 19:41:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E9=9D=A2=E6=9D=BF=E9=87=8D?= =?UTF-8?q?=E5=90=AF=E6=97=B6=E9=80=9A=E7=9F=A5agent=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/dashboard/main.go | 18 ++++++++++++++++++ go.mod | 2 +- go.sum | 3 ++- model/monitor.go | 3 ++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go index 2db7fed0ae..d05af21480 100644 --- a/cmd/dashboard/main.go +++ b/cmd/dashboard/main.go @@ -4,10 +4,12 @@ import ( "context" "fmt" "log" + "time" "github.com/naiba/nezha/cmd/dashboard/controller" "github.com/naiba/nezha/cmd/dashboard/rpc" "github.com/naiba/nezha/model" + "github.com/naiba/nezha/proto" "github.com/naiba/nezha/service/singleton" "github.com/ory/graceful" flag "github.com/spf13/pflag" @@ -68,6 +70,7 @@ func main() { go singleton.AlertSentinelStart() singleton.NewServiceSentinel(serviceSentinelDispatchBus) srv := controller.ServeWeb(singleton.Conf.HTTPPort) + go dispatchReportInfoTask() if err := graceful.Graceful(func() error { return srv.ListenAndServe() }, func(c context.Context) error { @@ -80,3 +83,18 @@ func main() { log.Printf("NEZHA>> ERROR: %v", err) } } + +func dispatchReportInfoTask() { + time.Sleep(time.Second * 15) + singleton.ServerLock.RLock() + defer singleton.ServerLock.RUnlock() + for _, server := range singleton.ServerList { + if server == nil || server.TaskStream == nil { + continue + } + server.TaskStream.Send(&proto.Task{ + Type: model.TaskTypeReportHostInfo, + Data: "", + }) + } +} diff --git a/go.mod b/go.mod index cef8cc5313..bface7c5d1 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/nicksnyder/go-i18n/v2 v2.4.0 github.com/ory/graceful v0.1.3 + github.com/oschwald/maxminddb-golang v1.13.1 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/robfig/cron/v3 v3.0.1 github.com/spf13/pflag v1.0.5 @@ -61,7 +62,6 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/oschwald/maxminddb-golang v1.13.1 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect diff --git a/go.sum b/go.sum index cdb105e1ca..e0cbf400cd 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= diff --git a/model/monitor.go b/model/monitor.go index 69c367c95c..ec1cd42ca4 100644 --- a/model/monitor.go +++ b/model/monitor.go @@ -13,7 +13,7 @@ import ( const ( _ = iota - TaskTypeHTTPGET + TaskTypeHTTPGet TaskTypeICMPPing TaskTypeTCPPing TaskTypeCommand @@ -22,6 +22,7 @@ const ( TaskTypeKeepalive TaskTypeTerminalGRPC TaskTypeNAT + TaskTypeReportHostInfo ) type TerminalTask struct {