學習filebeat入門

2021-10-11 21:50:59 字數 2801 閱讀 3808

入職新公司,讓我用filebeat 收集日誌輸出到kafka,做簡單的日誌收集工作

本機用的是mac os所以直接採用brew 安裝filebeat

brew install filebeat
安裝完成之後

 ~  filebeat version

filebeat version 7.10

.0(amd64)

, libbeat 7.10.0[

1428d58cf2ed945441fb2ed03961cafa9e4ad3eb built 2020-11

-0919:

57:03+

0000

utc]

brew install zookeeper
驗證完成

~  brew services list

name status user plist

tomcat stopped

zookeeper stopped

啟動zookeeper

brew services start zookeeper
驗證啟動

~  brew services list

name status user plist

tomcat stopped

zookeeper started dacheng.sun /users/dacheng.sun/library/launchagents/homebrew.mxcl.zookeeper.plist

brew 安裝kafka

brew install kafka
驗證安裝

~  brew services list

name status user plist

tomcat stopped

kafka stopped

zookeeper started dacheng.sun /users/dacheng.sun/library/launchagents/homebrew.mxcl.zookeeper.plist

啟動kafka

~  brew services start kafka

~  brew services list

name status user plist

tomcat stopped

kafka started dacheng.sun /users/dacheng.sun/library/launchagents/homebrew.mxcl.kafka.plist

zookeeper started dacheng.sun /users/dacheng.sun/library/launchagents/homebrew.mxcl.zookeeper.plist

func main() , "")

buf := byte(fd_content)

fd.write(buf)

time.sleep(2 * time.second)

}}

filebeat.inputs:

- type: log

enabled: true

paths:

- /data/deploy/makepolo/adserver/log.log #讀取檔案位置 完整路徑

#output.console: #這個是直接輸出到console的

# pretty: true

# enable: true

output.kafka:

hosts: ["127.0.0.1:9092"]

topic: filebeat_a_log

version: 2.0.0

enable: true

filebeat -e -c /filebeat_config_test.yml # 完整路徑
~  kafka-console-consumer --bootstrap-server localhost:9092 --topic filebeat_a_log --from-beginning

,"agent":,"ecs":,"log":},"message":"*****=2020-12-11 16:04:20*****test log","input":,"host":}

,"message":"*****=2020-12-11 16:04:22*****test log","input":,"ecs":,"host":,"agent":,"log":}}

,"host":,"agent":,"log":},"message":"*****=2020-12-11 16:04:24*****test log","input":,"ecs":}

,"log":},"message":"*****=2020-12-11 16:04:26*****test log","input":,"ecs":,"host":,"agent":}

filebeat 外掛程式開發

filebeat是乙個輕量的日誌收集工具,全套使用go語言開發。我目前遇到的問題是,在收集的時候需要對資料進行取樣,取樣比和取樣形式要靈活,因為可能在多個專案會使用到這個日誌收集功能。剛開始我仔細研究filebeat的配置,我感覺他自身應該帶有採集需求,然而並沒有。於是我想著去修改他的原始碼,這樣也...

filebeat 啟動流程

因為各種各樣的原因,好久沒有寫部落格了,還是希望能夠堅持下來 講解一下filebeat的啟動流程吧,核心功能先不描述了0.0 filebeat啟動入口在main.go檔案內,cmd.rootcmd.execute 啟動filebeat func main 在filebeat cmd root.go檔...

Filebeat工作原理

filebeat儲存檔案狀態 filebeat檢測事件策略 filebeat如何確保至少一次交付?filebeat如何避免資料重複?filebeat什麼情況會丟資料?總結前面幾節課我們講述了關於filebeat的一些基本應用和高階配置。本節課我們講深入 filebeat的原理,了解filebeat是...