1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
prospector.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
package udp
import (
"github.com/elastic/beats/filebeat/channel"
"github.com/elastic/beats/filebeat/harvester"
"github.com/elastic/beats/filebeat/prospector"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/libbeat/logp"
)
func init() {
err := prospector.Register("udp", NewProspector)
if err != nil {
panic(err)
}
}
type Prospector struct {
harvester *Harvester
started bool
outlet channel.Outleter
}
func NewProspector(cfg *common.Config, outlet channel.Factory, context prospector.Context) (prospector.Prospectorer, error) {
cfgwarn.Experimental("UDP prospector type is used")
out, err := outlet(cfg, context.DynamicFields)
if err != nil {
return nil, err
}
forwarder := harvester.NewForwarder(out)
return &Prospector{
outlet: out,
harvester: NewHarvester(forwarder, cfg),
started: false,
}, nil
}
func (p *Prospector) Run() {
if !p.started {
logp.Info("Starting udp prospector")
p.started = true
go func() {
defer p.outlet.Close()
err := p.harvester.Run()
if err != nil {
logp.Err("Error running harvester:: %v", err)
}
}()
}
}
func (p *Prospector) Stop() {
logp.Info("Stopping udp prospector")
p.harvester.Stop()
}
func (p *Prospector) Wait() {
p.Stop()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.2.4

搜索帮助