Skip to content

Commit

Permalink
Merge pull request #111 from TencentBlueKing/k8s-windows
Browse files Browse the repository at this point in the history
feat: 支持 windows 容器日志采集
  • Loading branch information
jayjiahua authored Dec 18, 2024
2 parents 349f0f1 + 6652eca commit 5d16cf6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
46 changes: 45 additions & 1 deletion beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"runtime"
"time"

"github.com/TencentBlueKing/bkmonitor-datalink/pkg/libgse/beat"
Expand Down Expand Up @@ -104,6 +106,44 @@ 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 {
if errors.Is(err, os.ErrNotExist) {
return 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.")
Expand All @@ -120,10 +160,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()
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

// 从配置目录
Expand Down

0 comments on commit 5d16cf6

Please sign in to comment.