1 Matching Annotations
  1. Jan 2022
    1. 我们来看filebeat的启动过程。 1、执行root命令 在filebeat/main.go文件中,main函数调用了cmd.RootCmd.Execute(),而RootCmd则是在cmd/root.go中被init函数初始化,其中就注册了filebeat.go:New函数以创建实现了beater接口的filebeat实例 对于任意一个beats来说,都需要有: 实现Beater接口的具体Beater(如Filebeat); 创建该具体Beater的(New)函数。 beater接口定义(beat/beat.go): type Beater interface { // The main event loop. This method should block until signalled to stop by an // invocation of the Stop() method. Run(b *Beat) error // Stop is invoked to signal that the Run method should finish its execution. // It will be invoked at most once. Stop() } 2、初始化和运行Filebeat 创建libbeat/cmd/instance/beat.go:Beat结构 执行(*Beat).launch方法 (*Beat).Init() 初始化Beat:加载beats公共config (*Beat).createBeater registerTemplateLoading: 当输出为es时,注册加载es模板的回调函数 pipeline.Load: 创建Pipeline:包含队列、事件处理器、输出等 setupMetrics: 安装监控 filebeat.New: 解析配置(其中输入配置包括配置文件中的Input和module Input)等 loadDashboards 加载kibana dashboard (*Filebeat).Run: 运行filebeat 3、Filebeat运行 设置加载es pipeline的回调函数 初始化registrar和crawler 设置事件完成的回调函数 启动Registrar、启动Crawler、启动Autodiscover 等待filebeat运行结束 我们再重代码看一下这个启动过程

      filebeat启动过程