Filebeat相關語法命令


Filebeat提供了一個用於運行Beat和執行常見任務的命令行界面,如測試配置文件和加載儀表板。 命令行還支持用於控制全局行為的全局標志。

常用的filebeat命令:

-E, --E "SETTING_NAME=VALUE"

覆蓋特定的配置設置。 您可以指定多個覆蓋。 例如:

filebeat -E "name=mybeat" -E "output.elasticsearch.hosts=["http://myhost:9200"]"

此設置適用於當前正在運行的Filebeat進程。 Filebeat配置文件不會更改。

-M, --M "VAR_NAME=VALUE"

覆蓋Filebeat模塊的默認配置。 您可以指定多個變量覆蓋。 例如:

filebeat -modules=nginx -M "nginx.access.var.paths=[/var/log/nginx/access.log*]" -M "nginx.access.var.pipeline=no_plugins"

-c, --c FILE

指定用於Filebeat的配置文件。 你在這里指定的文件是相對於path.config。 如果未指定-c標志,則使用默認配置文件filebeat.yml。

-d, --d SELECTORS

啟用對指定選擇器的調試。 對於選擇器,可以指定逗號分隔的組件列表,也可以使用-d“*”為所有組件啟用調試。 例如,-d“publish”顯示所有“publish”相關的消息。

-e, --e

記錄到stderr並禁用syslog /文件輸出。

-v, --v

記錄INFO級別的消息。

 

./filebeat -configtest 測試配置文件

./filebeat -httpprof[(host)]:(port):啟動http服務器進行性能分析

-memprofile (output file) :將存儲器配置文件寫入指定的輸出文件

-path.config : 設置配置的默認位置

-path.data : 設置數據文件的默認位置

-path.home : 設置其他文件的默認位置

-path.logs : 設置日志文件的默認位置

 

測試filebeat啟動后,查看相關輸出信息:

./filebeat -e -c filebeat.yml -d "publish"

后台方式啟動filebeat:

nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &  將所有標准輸出及標准錯誤輸出到/dev/null空設備,即沒有任何輸出
nohup ./filebeat -e -c filebeat.yml > filebeat.log & 

停止filebeat:

查找進程ID並kill掉:

ps -ef |grep filebeat
kill -9 進程號

 

 

############### Filebeat 配置文件說明#############

filebeat:

  # List of prospectors to fetch data.

  prospectors:

    -

      # paths指定要監控的日志

      paths:

        - /var/log/*.log

 

      #指定被監控的文件的編碼類型使用plain和utf-8都是可以處理中文日志的。

      # Some sample encodings:

      #   plain, utf-8, utf-16be-bom, utf-16be, utf-16le, big5, gb18030, gbk,

      #    hz-gb-2312, euc-kr, euc-jp, iso-2022-jp, shift-jis, ...

      #encoding: plain

 

      #指定文件的輸入類型log(默認)或者stdin。

      input_type: log

 

      # 在輸入中排除符合正則表達式列表的那些行

      # exclude_lines: ["^DBG"]

 

      # 包含輸入中符合正則表達式列表的那些行默認包含所有行include_lines執行完畢之后會執行exclude_lines。

      # include_lines: ["^ERR", "^WARN"]

 

      # 忽略掉符合正則表達式列表的文件默認為每一個符合paths定義的文件都創建一個harvester。

      # exclude_files: [".gz$"]

 

      # 向輸出的每一條日志添加額外的信息比如“level:debug”方便后續對日志進行分組統計。默認情況下會在輸出信息的fields子目錄下以指定的新增fields建立子目錄例如fields.level。

      #fields:

      #  level: debug

      #  review: 1

 

      # 如果該選項設置為true則新增fields成為頂級目錄而不是將其放在fields目錄下。自定義的field會覆蓋filebeat默認的field。

      #fields_under_root: false

 

      # 可以指定Filebeat忽略指定時間段以外修改的日志內容比如2h兩個小時或者5m(5分鍾)。

      #ignore_older: 0

 

      # 如果一個文件在某個時間段內沒有發生過更新則關閉監控的文件handle。默認1h,change只會在下一次scan才會被發現

      #close_older: 1h

 

      # i設定Elasticsearch輸出時的document的type字段也可以用來給日志進行分類。Default: log

      #document_type: log

 

      # Filebeat以多快的頻率去prospector指定的目錄下面檢測文件更新比如是否有新增文件如果設置為0s則Filebeat會盡可能快地感知更新占用的CPU會變高。默認是10s。

      #scan_frequency: 10s

 

      # 每個harvester監控文件時使用的buffer的大小。

      #harvester_buffer_size: 16384

 

      # 日志文件中增加一行算一個日志事件max_bytes限制在一次日志事件中最多上傳的字節數多出的字節會被丟棄。The default is 10MB.

      #max_bytes: 10485760

 

      # 適用於日志中每一條日志占據多行的情況比如各種語言的報錯信息調用棧。這個配置的下面包含如下配置

      #multiline:

 

        # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [

        #pattern: ^\[

 

        # Defines if the pattern set under pattern should be negated or not. Default is false.

        #negate: false

 

        # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern

        # that was (not) matched before or after or as long as a pattern is not matched based on negate.

        # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash

        #match: after

 

        # The maximum number of lines that are combined to one event.

        # In case there are more the max_lines the additional lines are discarded.

        # Default is 500

        #max_lines: 500

 

        # After the defined timeout, an multiline event is sent even if no new pattern was found to start a new event

        # Default is 5s.

        #timeout: 5s

 

      # 如果設置為trueFilebeat從文件尾開始監控文件新增內容把新增的每一行文件作為一個事件依次發送而不是從文件開始處重新發送所有內容。

      #tail_files: false

 

      # Filebeat檢測到某個文件到了EOF之后每次等待多久再去檢測文件是否有更新默認為1s。

      #backoff: 1s

 

      # Filebeat檢測到某個文件到了EOF之后等待檢測文件更新的最大時間默認是10秒。

      #max_backoff: 10s

 

      # 定義到達max_backoff的速度默認因子是2到達max_backoff后變成每次等待max_backoff那么長的時間才backoff一次直到文件有更新才會重置為backoff。

      #backoff_factor: 2

 

      # 這個選項關閉一個文件,當文件名稱的變化。#該配置選項建議只在windows。

      #force_close_files: false

 

    # Additional prospector

    #-

      # Configuration to use stdin input

      #input_type: stdin

 

  # spooler的大小spooler中的事件數量超過這個閾值的時候會清空發送出去不論是否到達超時時間。

  #spool_size: 2048

 

  # 是否采用異步發送模式(實驗!)

  #publish_async: false

 

  # spooler的超時時間如果到了超時時間spooler也會清空發送出去不論是否到達容量的閾值。

  #idle_timeout: 5s

 

  # 記錄filebeat處理日志文件的位置的文件

  registry_file: /var/lib/filebeat/registry

 

  # 如果要在本配置文件中引入其他位置的配置文件可以寫在這里需要寫完整路徑但是只處理prospector的部分。

  #config_dir:

 

 

############################# Output ##########################################

 

# 輸出到數據配置.單個實例數據可以輸出到elasticsearch或者logstash選擇其中一種注釋掉另外一組輸出配置。

output:

 

  ### 輸出數據到Elasticsearch

  elasticsearch:

    # IPv6 addresses should always be defined as: https://[2001:db8::1]:9200

    hosts: ["localhost:9200"]

 

    # 輸出認證.

    #protocol: "https"

    #username: "admin"

    #password: "s3cr3t"

 

    # 啟動進程數.

    #worker: 1

 

    # 輸出數據到指定index default is "filebeat"  可以使用變量[filebeat-]YYYY.MM.DD keys.

    #index: "filebeat"

 

    # 一個模板用於設置在Elasticsearch映射默認模板加載是禁用的,沒有加載模板這些設置可以調整或者覆蓋現有的加載自己的模板

    #template:

 

      # Template name. default is filebeat.

      #name: "filebeat"

 

      # Path to template file

      #path: "filebeat.template.json"

 

      # Overwrite existing template

      #overwrite: false

 

    # Optional HTTP Path

    #path: "/elasticsearch"

 

    # Proxy server url

    #proxy_url: http://proxy:3128

 

    # 發送重試的次數取決於max_retries的設置默認為3

    #max_retries: 3

 

    # 單個elasticsearch批量API索引請求的最大事件數。默認是50。

    #bulk_max_size: 50

 

    # elasticsearch請求超時事件。默認90秒.

    #timeout: 90

 

    # 新事件兩個批量API索引請求之間需要等待的秒數。如果bulk_max_size在該值之前到達額外的批量索引請求生效。

    #flush_interval: 1

 

    # elasticsearch是否保持拓撲。默認false。該值只支持Packetbeat。

    #save_topology: false

 

    # elasticsearch保存拓撲信息的有效時間。默認15秒。

    #topology_expire: 15

 

    # 配置TLS參數選項如證書頒發機構等用於基於https的連接。如果tls丟失主機的CAs用於https連接elasticsearch。

    #tls:

      # List of root certificates for HTTPS server verifications

      #certificate_authorities: ["/etc/pki/root/ca.pem"]

 

      # Certificate for TLS client authentication

      #certificate: "/etc/pki/client/cert.pem"

 

      # Client Certificate Key

      #certificate_key: "/etc/pki/client/cert.key"

 

      # Controls whether the client verifies server certificates and host name.

      # If insecure is set to true, all server host names and certificates will be

      # accepted. In this mode TLS based connections are susceptible to

      # man-in-the-middle attacks. Use only for testing.

      #insecure: true

 

      # Configure cipher suites to be used for TLS connections

      #cipher_suites: []

 

      # Configure curve types for ECDHE based cipher suites

      #curve_types: []

 

      # Configure minimum TLS version allowed for connection to logstash

      #min_version: 1.0

 

      # Configure maximum TLS version allowed for connection to logstash

      #max_version: 1.2

 

 

  ### 發送數據到logstash 單個實例數據可以輸出到elasticsearch或者logstash選擇其中一種注釋掉另外一組輸出配置。

  #logstash:

    # Logstash 主機地址

    #hosts: ["localhost:5044"]

 

    # 配置每個主機發布事件的worker數量。在負載均衡模式下最好啟用。

    #worker: 1

 

    # #發送數據壓縮級別

    #compression_level: 3

 

    # 如果設置為TRUE和配置了多台logstash主機輸出插件將負載均衡的發布事件到所有logstash主機。

    #如果設置為false輸出插件發送所有事件到隨機的一台主機上如果選擇的不可達將切換到另一台主機。默認是false。

    #loadbalance: true

 

    # 輸出數據到指定index default is "filebeat"  可以使用變量[filebeat-]YYYY.MM.DD keys.

    #index: filebeat

 

    # Optional TLS. By default is off.

    #配置TLS參數選項如證書頒發機構等用於基於https的連接。如果tls丟失主機的CAs用於https連接elasticsearch。

    #tls:

      # List of root certificates for HTTPS server verifications

      #certificate_authorities: ["/etc/pki/root/ca.pem"]

 

      # Certificate for TLS client authentication

      #certificate: "/etc/pki/client/cert.pem"

 

      # Client Certificate Key

      #certificate_key: "/etc/pki/client/cert.key"

 

      # Controls whether the client verifies server certificates and host name.

      # If insecure is set to true, all server host names and certificates will be

      # accepted. In this mode TLS based connections are susceptible to

      # man-in-the-middle attacks. Use only for testing.

      #insecure: true

 

      # Configure cipher suites to be used for TLS connections

      #cipher_suites: []

 

      # Configure curve types for ECDHE based cipher suites

      #curve_types: []

 

 

  ### 文件輸出將事務轉存到一個文件每個事務是一個JSON格式。主要用於測試。也可以用作logstash輸入。

  #file:

    # 指定文件保存的路徑。

    #path: "/tmp/filebeat"

 

    # 文件名。默認是 Beat 名稱。上面配置將生成 packetbeat, packetbeat.1, packetbeat.2 等文件。

    #filename: filebeat

 

    # 定義每個文件最大大小。當大小到達該值文件將輪滾。默認值是1000 KB

    #rotate_every_kb: 10000

 

    # 保留文件最大數量。文件數量到達該值將刪除最舊的文件。默認是7一星期。

    #number_of_files: 7

 

 

  ### Console output 標准輸出JSON 格式。

  # console:

    #如果設置為TRUE事件將很友好的格式化標准輸出。默認false。

    #pretty: false

 

 

############################# Shipper #########################################

 

shipper:

  # #日志發送者信息標示

  # 如果沒設置以hostname名自居。該名字包含在每個發布事務的shipper字段。可以以該名字對單個beat發送的所有事務分組。

  #name:

 

  # beat標簽列表包含在每個發布事務的tags字段。標簽可用很容易的按照不同的邏輯分組服務器。

  #例如一個web集群服務器可以對beat添加上webservers標簽然后在kibana的visualisation界面以該標簽過濾和查詢整組服務器。

  #tags: ["service-X", "web-tier"]

 

  # 如果啟用了ignore_outgoing選項beat將忽略從運行beat服務器上所有事務。

  #ignore_outgoing: true

 

  # 拓撲圖刷新的間隔。也就是設置每個beat向拓撲圖發布其IP地址的頻率。默認是10秒。

  #refresh_topology_freq: 10

 

  # 拓撲的過期時間。在beat停止發布其IP地址時非常有用。當過期后IP地址將自動的從拓撲圖中刪除。默認是15秒。

  #topology_expire: 15

 

  # Internal queue size for single events in processing pipeline

  #queue_size: 1000

 

  # GeoIP數據庫的搜索路徑。beat找到GeoIP數據庫后加載然后對每個事務輸出client的GeoIP位置目前只有Packetbeat使用該選項。

  #geoip:

    #paths:

    #  - "/usr/share/GeoIP/GeoLiteCity.dat"

    #  - "/usr/local/var/GeoIP/GeoLiteCity.dat"

 

 

############################# Logging #########################################

 

 

# 配置beats日志。日志可以寫入到syslog也可以是輪滾日志文件。默認是syslog。

logging:

 

  # 如果啟用發送所有日志到系統日志。

  #to_syslog: true

 

  # 日志發送到輪滾文件。

  #to_files: false

 

  # 

  files:

    # 日志文件目錄。

    #path: /var/log/mybeat

 

    # 日志文件名稱

    #name: mybeat

 

    # 日志文件的最大大小。默認 10485760 (10 MB)。

    rotateeverybytes: 10485760 # = 10MB

 

    # 保留日志周期。 默認 7。值范圍為2 到 1024。

    #keepfiles: 7

 

  # Enable debug output for selected components. To enable all selectors use ["*"]

  # Other available selectors are beat, publish, service

  # Multiple selectors can be chained.

  #selectors: [ ]

 

  # 日志級別。debug, info, warning, error 或 critical。如果使用debug但沒有配置selectors* selectors將被使用。默認error。

  #level: error

 

  #參考文檔

  #http://blog.51cto.com/michaelkang/1864225

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM