Java笔记··By/蜜汁炒酸奶

logstash6配置文件结构

配置文件的结构

对于要添加到事件处理管道的每种类型的插件,Logstash配置文件都有一个单独的区域(section)。

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

filter {
  ...
}

output {
  ...
}
1
2
3
4
5
6
7
8
9
10
11
12
13

Logstash 用 {} 来定义区域(section )。区域内可以包括插件区域定义,你可以在一个区域内定义多个插件。插件区域内则可以定义键值对设置。

插件配置结构

插件的配置包括插件名称,其后跟该插件的设置块。如下面的input区域定义了两个File组件:

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

  file {
    path => "/var/log/apache/access.log"
    type => "apache"
  }
}
1
2
3
4
5
6
7
8
9
10
11

在此示例中,为每个文件输入配置了两个设置:路径和类型。
您可以配置的设置因插件类型而异。
详情可见 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} ]
1
  • Lists
path => [ "/var/log/messages", "/var/log/*.log" ]
uris => [ "http://elastic.co", "http://example.net" ]
1
2
  • Boolean
ssl_enable => true
1
  • Bytes
  my_bytes => "1113"   # 1113 bytes
  my_bytes => "10MiB"  # 10485760 bytes
  my_bytes => "100kib" # 102400 bytes
  my_bytes => "180 mb" # 180000000 bytes
1
2
3
4
  • Codec
 codec => "json"
1
  • Hash
match => {
  "field1" => "value1"
  "field2" => "value2"
  ...
}
1
2
3
4
5
  • Numbers
port => 33
1
  • Password
my_password => "password"
1
  • URI
my_uri => "http://foo:bar@example.net" 
1
  • Path
my_path => "/tmp/logstash"
1
  • string
host => "hostname"
1
  • 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'
1
2
  • Comments
    注释
# this is a comment

input { # comments can appear at the end of a line, too
  # ...
}  
1
2
3
4
5

参考资料

Structure of a Config File

配置语法

预览
Loading comments...
0 条评论

暂无数据

example
预览