logstash6配置文件結構

  • 2020 年 1 月 21 日
  • 筆記

配置文件的結構

對於要添加到事件處理管道的每種類型的插件,Logstash配置文件都有一個單獨的區域(section)。

# This is a comment. You should use comments to describe  # parts of your configuration.  input {    ...  }    filter {    ...  }    output {    ...  }

Logstash 用 {} 來定義區域(section )。區域內可以包括插件區域定義,你可以在一個區域內定義多個插件。插件區域內則可以定義鍵值對設置。

插件配置結構

插件的配置包括插件名稱,其後跟該插件的設置塊。如下面的input區域定義了兩個File組件:

input {    file {      path => "/var/log/messages"      type => "syslog"    }      file {      path => "/var/log/apache/access.log"      type => "apache"    }  }

在此示例中,為每個文件輸入配置了兩個設置:路徑和類型。 您可以配置的設置因插件類型而異。 詳情可見 Input Plugins, Output PluginsFilter Plugins, 以及 Codec Plugins

插件

用途

Input Plugins

輸入插件,使Logstash能夠讀取特定的事件源。

Output Plugins

輸出插件 ,輸出插件將事件數據發送到特定目標。輸出是事件管道的最後階段。本身支持多輸出配置。

Filter Plugins

過濾器插件對事件執行中間處理。過濾器通常根據事件的特徵有條件地應用。

Codec Plugins

過濾器插件對事件執行中間處理。過濾器通常根據事件的特徵有條件地應用。

工作原理

Logstash事件處理管道有三個階段:輸入→過濾器→輸出。

輸入生成事件,過濾器修改它們,輸出將它們發送到其他地方。

輸入和輸出支持編解碼器,使您能夠在數據進入或退出管道時對數據進行編碼或解碼,而無需使用單獨的過濾器。

數據類型

插件可以要求設置的值為特定類型,例如布爾值(boolean),列表(list)或散列(hash)。支持的值類型如下:

  • Array
users => [ {id => 1, name => bob}, {id => 2, name => jane} ]
  • Lists
path => [ "/var/log/messages", "/var/log/*.log" ]  uris => [ "http://elastic.co", "http://example.net" ]
  • Boolean
ssl_enable => true
  • Bytes
  my_bytes => "1113"   # 1113 bytes    my_bytes => "10MiB"  # 10485760 bytes    my_bytes => "100kib" # 102400 bytes    my_bytes => "180 mb" # 180000000 bytes
  • Codec
 codec => "json"
  • Hash
match => {    "field1" => "value1"    "field2" => "value2"    ...  }
  • Numbers port => 33
  • Password
my_password => "password"
  • URI
my_uri => "http://foo:[email protected]" 
  • Path
my_path => "/tmp/logstash"
  • string
host => "hostname"
  • Escape sequences 默認情況下,不啟用轉義序列。如果您希望在帶引號的字符串中使用轉義序列,則需要在logstash.yml中設置config.support_escapes:true。如果為true,則引用的字符串(double和single)將具有此轉換:

Text

Result

r

carriage return (ASCII 13)

n

new line (ASCII 10)

t

tab (ASCII 9)

backslash (ASCII 92)

"

double quote (ASCII 34)

'

single quote (ASCII 39)

  name => "Hello world"    name => 'It's a beautiful day'
  • Comments 注釋
# this is a comment    input { # comments can appear at the end of a line, too    # ...  }  

### 參考資料 Structure of a Config File

配置語法