From cbccdf1aa3324b1653a41332631c43672a446d9c Mon Sep 17 00:00:00 2001 From: chenjiandongx Date: Thu, 12 Dec 2024 12:22:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20windows=20?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E6=97=A5=E5=BF=97=E9=87=87=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beater/beater.go | 43 ++++++++++++++++++++++++++++++++++++++++++- config/config.go | 1 + 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/beater/beater.go b/beater/beater.go index 0b0f1b3..a586109 100644 --- a/beater/beater.go +++ b/beater/beater.go @@ -30,6 +30,8 @@ import ( "context" "encoding/json" "fmt" + "os" + "runtime" "time" "github.com/TencentBlueKing/bkmonitor-datalink/pkg/libgse/beat" @@ -104,6 +106,41 @@ func (bt *LogBeat) PublishEvent(event beat.MapStr) bool { return beat.Send(event) } +func (bt *LogBeat) windowsReload() { + if !beat.IsContainerMode() { + return + } + + var modTime time.Time + checkFunc := func() error { + fileInfo, err := os.Stat(bt.config.WindowsReloadPath) + if err != nil { + return err + } + + if fileInfo.ModTime() != modTime { + select { + case beat.ReloadChan <- true: + default: + } + } + modTime = fileInfo.ModTime() + return nil + } + + ticker := time.NewTicker(time.Second * 10) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + if err := checkFunc(); err != nil { + logp.L.Errorf("failed to check windows reload path: %s", err) + } + } + } +} + // Run beater interface func (bt *LogBeat) Run() error { logp.L.Infof("logbeat is running! Hit CTRL-C to stop it.") @@ -120,10 +157,14 @@ func (bt *LogBeat) Run() error { } defer Registrar.Stop() - if err := bt.manager.Start(); nil != err { + if err := bt.manager.Start(); err != nil { logp.L.Error("failed to start manager ") } + if runtime.GOOS == "windows" { + go bt.windowsReload() + } + reloadTicker := time.NewTicker(10 * time.Second) diffTaskTicker := time.NewTicker(60 * time.Second) defer diffTaskTicker.Stop() diff --git a/config/config.go b/config/config.go index cf3bcef..fbb589b 100644 --- a/config/config.go +++ b/config/config.go @@ -56,6 +56,7 @@ type Config struct { IgnoreCmdbLevel bool `config:"ignore_cmdb_level"` MustHostIDExist bool `config:"must_host_id_exist"` CheckDiff bool `config:"check_diff"` + WindowsReloadPath string `config:"windows_reload_path"` } // 从配置目录 From 6652eca91510bd2ee2ac1c2b642592e484ee274b Mon Sep 17 00:00:00 2001 From: chenjiandongx Date: Wed, 18 Dec 2024 14:28:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=E5=BC=82=E5=B8=B8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beater/beater.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beater/beater.go b/beater/beater.go index a586109..fb50f1c 100644 --- a/beater/beater.go +++ b/beater/beater.go @@ -115,6 +115,9 @@ func (bt *LogBeat) windowsReload() { checkFunc := func() error { fileInfo, err := os.Stat(bt.config.WindowsReloadPath) if err != nil { + if errors.Is(err, os.ErrNotExist) { + return nil + } return err }