fluentd输入输出插件区别和用法

fluentd不同输入插件区别和用法

1.in_tail插件

in_tail输入插件允许fluentd从text文件尾部读取事件,与tail -F命令相似.

Example Configuration

in_tail is included in Fluentd’s core. No additional installation process is required.


  @type tail  #required
  path /var/log/httpd-access.log  #required
  pos_file /var/log/td-agent/httpd-access.log.pos #记录td-agent重启前读取的的位置(强烈推荐)
  tag apache.access  #required
  format apache2

2.in_forward插件

in_forward输入插件监听一个 TCP socket接收事件流.也监听UDP socket 接收心跳消息.此插件主要用于从其他Fluentd实例,fluent-cat命令或客户端库接收事件日志。这是迄今为止检索记录的最有效方法。

注意: 如果没有安全连接,请勿将此插件用于DC间或公共互联网数据传输。为了提供可靠/低延迟的传输,我们假设此插件仅在专用网络中使用。 如果您打开此插件的端口到Internet,攻击者可以通过使用特定数据包轻松崩溃Fluentd。如果您需要节点之间的安全连接,请考虑使用in_secure_forward。

Example Configuration

in_forward is included in Fluentd’s core. No additional installation process is required.


  @type forward  #required
  port 24224
  bind 0.0.0.0

3.in_secure_forward插件

in_secure_forward输入插件通过SSL接受带有身份验证的消息.

in_secure_forward不包含在td-agent包或fluentd gem中。要安装它,请参阅https://docs.fluentd.org/v0.12/articles/plugin-management

Example Configuration

首先,通过secure-forward-ca-generate生成私有CA文件,然后通过安全方式(scp或其他方式)将该文件复制到输出插件端。


  @type secure_forward
  shared_key      secret_string
  self_hostname   server.fqdn.local  # This fqdn is used as CN (Common Name) of certificates
  secure true
  ca_cert_path        /path/to/certificate/ca_cert.pem
  ca_private_key_path /path/to/certificate/ca_key.pem
  ca_private_key_passphrase passphrase_for_private_CA_secret_key

4.in_udp插件

in_udp Input插件使Fluentd能够接受UDP有效负载。

Example Configuration

in_udp is included in Fluentd’s core. No additional installation process is required.


  @type udp
  tag mytag # required
  format /^(?\d+):(?\w+)$/ # required
  port 20001 # optional. 5160 by default
  bind 0.0.0.0 # optional. 0.0.0.0 by default
  body_size_limit 1MB # optional. 4096 bytes by default

5.in_tcp插件

in_tcp Input插件使Fluentd能够接受TCP有效负载。 不要使用此插件从客户端库接收日志。对这种情况使用in_forward。

Example Configuration

in_tcp is included in Fluentd’s core. No additional installation process is required.


  @type tcp
  tag tcp.events # required
  format /^(?\d+):(?\w+)$/ # required
  port 20001 # optional. 5170 by default
  bind 0.0.0.0 # optional. 0.0.0.0 by default
  delimiter \n # optional. \n (newline) by default

6.in_http插件

n_http Input插件使Fluentd能够从HTTP POST中检索记录。 URL路径成为Fluentd事件日志的标记,POSTed body元素成为记录本身。

Example Cofiguration

in_http is included in Fluentd’s core. No additional installation process is required.


  @type http
  port 8888
  bind 0.0.0.0
  body_size_limit 32m
  keepalive_timeout 10s

7.in_unix 插件

in_unix Input插件使Fluentd能够从Unix Domain Socket中检索记录。有线协议与in_forward相同,但传输层不同。

Example Configuration

in_unix is included in Fluentd’s core. No additional installation process is required.


  @type unix #required
  path /path/to/socket.sock #required

8.in_syslog插件

in_syslog输入插件使Fluentd能够通过UDP或TCP上的syslog协议检索记录。

Example Configuration

in_syslog is included in Fluentd’s core. No additional installation process is required.


  @type syslog
  port 5140
  bind 0.0.0.0
  tag system

9.in_exec插件

in_exec输入插件执行外部程序以接收或拉取事件日志。然后它将从程序的标准输出中读取TSV(制表符分隔值),JSON或MessagePack。 您可以定期或永久地运行程序。要定期运行,请使用run_interval参数。

Example Configuration

in_exec is included in Fluentd’s core. No additional installation process is required.


  @type exec #required
  command cmd arg arg #required
  keys k1,k2,k3
  tag_key k1
  time_key k2
  time_format %Y-%m-%d %H:%M:%S
  run_interval 10s

10.in_scribe插件

in_scribe输入插件使Fluentd能够通过Scribe协议检索记录。 Scribe是另一个由Facebook开源的日志收集器守护程序。 由于Scribe最近维护得不好,因此该插件对于希望将Fluentd与现有Scribe基础架构一起使用的现有Scribe用户非常有用。

install

in_scribe默认包含在td-agent中。Fluentd gem用户需要使用以下命令安装fluent-plugin-scribe gem:

$ fluent-gem install fluent-plugin-scribe

Example Configuration


  @type scribe
  port 1463

  bind 0.0.0.0
  msg_format json

11.in_multiprocess插件

默认情况下,Fluentd仅在系统上使用单个CPU核心。 in_multiprocess输入插件使Fluentd能够通过生成多个子进程来使用多个CPU核心。一个Fluentd用户使用此插件每天处理10亿条记录。

install

默认情况下,in_multiprocess不包含在td-agent中。 td-agent用户必须手动安装fluent-plugin-multiprocess。

  • Fluentd: fluent-gem install fluent-plugin-multiprocess
  • td-agent v2: /usr/sbin/td-agent-gem install fluent-plugin-multiprocess
  • td-agent v1: /usr/lib/fluent/ruby/bin/fluent-gem install fluent-plugin-multiprocess

Example Configuration


  @type multiprocess #required

   #required
    cmdline -c /etc/fluent/fluentd_child1.conf --log /var/log/fluent/fluentd_child1.log
    sleep_before_start 1s
    sleep_before_shutdown 5s
  
  
    cmdline -c /etc/fluent/fluentd_child2.conf --log /var/log/fluent/fluentd_child2.log
    sleep_before_start 1s
    sleep_before_shutdown 5s
  
  
    cmdline -c /etc/fluent/fluentd_child3.conf --log /var/log/fluent/fluentd_child3.log
    sleep_before_start 1s
    sleep_before_shutdown 5s
  

12.in_dummy插件

in_dummy输入插件生成虚拟事件。它对于Fluentd的测试,调试,基准测试和入门非常有用。

Example Configuration

in_dummy is included in Fluentd’s core. No additional installation process is required.


  @type dummy #required
  dummy {"hello":"world"} #required

fluentd不同输出插件区别和用法

1.out_file插件

out_file TimeSliced Output插件将事件写入文件。默认情况下,它每天创建文件(大约00:10)。这意味着当您首次使用插件导入记录时,不会立即创建任何文件。满足time_slice_format条件时将创建该文件。要更改输出频率,请修改time_slice_format值。

Example Configuration

out_file is included in Fluentd’s core. No additional installation process is required.


  @type file #required
  path /var/log/fluent/myapp #required
  time_slice_format %Y%m%d
  time_slice_wait 10m
  time_format %Y%m%dT%H%M%S%z
  compress gzip
  utc

2.out_s3插件

out_s3 TimeSliced Output插件将记录写入Amazon S3云对象存储服务。默认情况下,它每小时创建一次文件。这意味着当您首次使用插件导入记录时,不会立即创建任何文件。满足time_slice_format条件时将创建该文件。要更改输出频率,请修改time_slice_format值。

Installation

out_s3默认包含在td-agent中。fluentd gem用户需要使用以下命令安装fluent-plugin-s3 gem。

$ fluent-gem install fluent-plugin-s3

Example Configuration


  @type s3 #required

  aws_key_id YOUR_AWS_KEY_ID
  aws_sec_key YOUR_AWS_SECRET_KEY
  s3_bucket YOUR_S3_BUCKET_NAME
  s3_region ap-northeast-1
  path logs/
  buffer_path /var/log/fluent/s3

  time_slice_format %Y%m%d%H
  time_slice_wait 10m
  utc

  buffer_chunk_limit 256m

3.out_kafka插件

out_kafka输出插件将记录写入Apache Kafka。

Installation

在v2.3.3之后,out_kafka包含在td-agent2中。fluentd gem用户需要使用以下命令安装fluent-plugin-kafka gem。

$ fluent-gem install fluent-plugin-kafka

Example Configuration


  @type kafka_buffered #required

  # list of seed brokers
  brokers :,:

  # buffer settings
  buffer_type file
  buffer_path /var/log/td-agent/buffer/td
  flush_interval 3s

  # topic settings
  default_topic messages

  # data type settings
  output_data_type json
  compression_codec gzip

  # producer settings
  max_send_retries 1
  required_acks -1

4.out_forward插件

out_forward Buffered Output插件将事件转发给其他fluentd的节点。此插件支持负载平衡和自动故障转移(例如,主动 - 主动备份)。要进行复制,请使用out_copy插件。 out_forward插件使用“φaccrual failure detector”算法检测服务器故障。您可以自定义算法的参数。当服务器故障恢复时,插件会在几秒钟后自动使服务器可用。 out_forward插件支持最多一次和至少一次语义。默认值是最多一次。

Example Configuration

out_forward is included in Fluentd’s core. No additional installation process is required.


  @type forward
  send_timeout 60s
  recover_wait 10s
  hard_timeout 60s

  
    name myserver1
    host 192.168.1.3
    port 24224
    weight 60
  
  
    name myserver2
    host 192.168.1.4
    port 24224
    weight 60
  
  ...

  
    @type file
    path /var/log/fluent/forward-failed
  

5.out_secure_forward插件

out_secure_forward输出插件通过SSL通过身份验证发送消息.

Installation

out_secure_forward不包含在td-agent包或流利的gem中。要安装它,请参阅https://docs.fluentd.org/v0.12/articles/plugin-management

Example Configuration

首先,通过secure-forward-ca-generate在输入插件一侧生成私有CA文件,然后通过安全方式(scp或其他方式)将该文件复制到输出插件端。


  @type secure_forward
  shared_key secret_string
  self_hostname client.fqdn.local
  secure true
  ca_cert_path /path/to/certificate/ca_cert.pem

  
    host server.fqdn.local  # or IP
    # port 24284
  

注: 如果没有主机名ACL(尚未实现),则不会在任何状态下检查self_hostname。 “#{Socket.gethostname}”`占位符可用于此类情况。


  @type secure_forward
  shared_key secret_string
  self_hostname "#{Socket.gethostname}"
  secure true
  ca_cert_path /path/to/certificate/ca_cert.pem

  
    host server.fqdn.local  # or IP
    # port 24284
  

6.out_exec插件

out_exec TimeSliced Output插件将事件传递给外部程序。程序接收包含传入事件作为其最后一个参数的文件的路径。默认情况下,文件格式是制表符分隔值(TSV)。

Example Configuration

out_exec is included in Fluentd’s core. No additional installation process is required.


  @type exec
  command cmd arg arg
  format tsv
  keys k1,k2,k3
  tag_key k1
  time_key k2
  time_format %Y-%m-%d %H:%M:%S

7.out_exec_filter插件

out_exec_filter缓冲输出插件(1)使用事件作为输入执行外部程序,以及(2)从程序输出中读取新事件。它将制表符分隔值(TSV)传递给stdin,默认情况下从stdout读取TSV。

Example Configuration

out_exec_filter is included in Fluentd’s core. No additional installation process is required.


  @type exec_filter
  command cmd arg arg
  in_keys k1,k2,k3
  out_keys k1,k2,k3,k4
  tag_key k1
  time_key k2
  time_format %Y-%m-%d %H:%M:%S

8.copy插件

复制输出插件将事件复制到多个输出。

Example Configuration

out_copy is included in Fluentd’s core. No additional installation process is required.


  @type copy
  
    @type file
    path /var/log/fluent/myapp1
    ...
  
  
    ...
  
  
    ...
  

默认情况下,out_copy在store插件之间共享一条记录。 当deep_copy为true时,out_copy将不同的记录传递给每个store插件。

: 指定存储目标。格式与指令相同。

9.out_geoip插件

ut_geoip Buffered Output插件使用Maxmind GeoIP数据库将地理位置信息添加到日志中。

Prerequisites

The GeoIP library.

:::term # for RHEL/CentOS $ sudo yum install geoip-devel –enablerepo=epel

# for Ubuntu/Debian $ sudo apt-get install libgeoip-dev

# for MacOSX (brew) $ brew install geoip

Install

out_geoip不包含在td-agent中。所有用户必须使用以下命令安装fluent-plugin-geoip gem。

$ fluent-gem install fluent-plugin-geoip
$ sudo /usr/sbin/td-agent-gem install fluent-plugin-geoip

Example Configuration


  @type geoip
  geoip_lookup_key        host
  enable_key_country_code geoip_country
  enable_key_city         geoip_city
  enable_key_latitude     geoip_lat
  enable_key_longitude    geoip_lon
  remove_tag_prefix       test.
  add_tag_prefix          geoip.
  flush_interval          5s



:::text
# original record
test.message {
  "host":"66.102.9.80",
  "message":"test"
}

# output record
geoip.message: {
  "host":"66.102.9.80",
  "message":"test",
  "geoip_country":"US",
  "geoip_city":"Mountain View",
  "geoip_lat":37.4192008972168,
  "geoip_lon":-122.05740356445312
}

10.roundrobin插件

roundrobin Output插件使用循环算法将事件分配到多个输出。

Example Configuration

out_roundrobin is included in Fluentd’s core. No additional installation process is required.


  @type roundrobin

  
    @type tcp
    host 192.168.1.21
    ...
  
  
    ...
  
  
    ...
  

11.stdout插件

stdout输出插件将事件打印到stdout(如果使用守护程序模式启动,则打印日志)。此输出插件可用于调试目的。

Example Configuration

out_stdout is included in Fluentd’s core. No additional installation process is required.


  @type stdout

12.null插件

null输出插件只会丢弃事件。

Example Configuration

out_null` is included in Fluentd’s core. No additional installation process is required.


  @type null

13.out_webhdfs插件

out_webhdfs TimeSliced Output插件将记录写入HDFS(Hadoop分布式文件系统)。默认情况下,它每小时创建一次文件。这意味着当您首次使用插件导入记录时,不会立即创建任何文件。满足time_slice_format条件时将创建该文件。要更改输出频率,请修改time_slice_format值。

Install

out_webhdfs默认包含在td-agent中(v1.1.10或更高版本), fluentd gem用户必须使用以下命令安装fluent-plugin-webhdfs gem。

$ fluent-gem install fluent-plugin-webhdfs

HDFS Configuration

默认情况下,CDH上未启用追加操作。请将这些配置放入hdfs-site.xml文件并重新启动整个群集。

:CHD:Cloudera版本(Cloudera’s Distribution Including Apache Hadoop,简称“CDH”),基于Web的用户界面,支持大多数Hadoop组件,包括HDFS、MapReduce、Hive、Pig、 Hbase、Zookeeper、Sqoop,简化了大数据平台的安装、使用难度。


  dfs.webhdfs.enabled
  true



  dfs.support.append
  true



  dfs.support.broken.append
  true

Example Configuration


  @type webhdfs
  host namenode.your.cluster.local
  port 50070
  path "/path/on/hdfs/access.log.%Y%m%d_%H.#{Socket.gethostname}.log"
  flush_interval 10s

14.out_mongo插件

out_mongo Buffered Output插件将记录写入MongoDB,即面向文档的新兴数据库系统MongoDB。

Fluentd使您的应用程序可以通过批量插入异步插入MongoDB记录,而不像直接插入应用程序中的记录。这具有以下优点:

1.对应用程序性能影响较小

2.在维护JSON记录结构的同时提高MongoDB插入吞吐量

Install

out_mongo默认包含在td-agent中。fluentd gem用户需要使用以下命令安装fluent-plugin-mongo gem。

$ fluent-gem install fluent-plugin-mongo

Example Configuration

# Single MongoDB

  @type mongo
  host fluentd
  port 27017
  database fluentd
  collection test

  # for capped collection
  capped
  capped_size 1024m

  # authentication
  user michael
  password jordan

  # key name of timestamp
  time_key time

  # flush
  flush_interval 10s

15.out_mongo_replset插件

out_mongo_replset缓冲输出插件将记录写入MongoDB,即面向文档的新兴数据库系统MongoDB。

Install

out_mongo_replset默认包含在td-agent中, fluentd gem用户需要使用以下命令安装fluent-plugin-mongo gem。

$ fluent-gem install fluent-plugin-mongo

Example Configuration

# Single MongoDB

  @type mongo_replset
  database fluentd
  collection test
  nodes localhost:27017,localhost:27018,localhost:27019

  # flush
  flush_interval 10s

16.relable插件

relabel输出插件重新标记事件。

Example Configuration

out_relabel is included in Fluentd’s core. No additional installation process is required.


  @type relabel
  @label @foo



上面的示例将标签@foo放到匹配的事件中,label指令可以处理这些事件。 仅供参考:所有输入和输出插件也都有由Fluentd核心提供的@label参数。 relabel插件是一个实际上什么都不做的插件,但只支持@label参数。

17.out_rewrite_tag_filter插件

out_rewrite_tag_filter输出插件旨在重写像mod_rewrite这样的标记。当值与正则表达式匹配/不匹配时,使用重写标记重新发出记录。您还可以使用正则表达式按域,状态代码(例如500错误),用户代理,请求-URI,正则表达式反向引用等更改apache日志中的标记。

Install

out_rewrite_tag_filter默认包含在td-agent中(v1.1.18或更高版本)。fluentd gem用户必须使用以下命令安装fluent-plugin-rewrite-tag-filter gem。

$ fluent-gem install fluent-plugin-rewrite-tag-filter

Example Configuration

配置设计首先丢弃一些模式记录,然后重新发出其他匹配记录作为新标记名称。


  @type rewrite_tag_filter
  capitalize_regex_backreference yes
  
    key     path
    pattern \.(gif|jpe?g|png|pdf|zip)$
    tag     clear
  
  
    key     status #应用正则表达式的字段名称
    pattern ^200$ #正则表达式
    tag     clear #新标签
    invert  true  #如果为true,则在不匹配模式时重写标记
  
  
    key     domain
    pattern ^.+\.com$
    tag     clear
    invert  true
  
  
    key     domain
    pattern ^maps\.example\.com$
    tag     site.ExampleMaps
  
  
    key     domain
    pattern ^news\.example\.com$
    tag     site.ExampleNews
  
  # it is also supported regexp back reference.
  
    key     domain
    pattern ^(mail)\.(example)\.com$
    tag     site.$2$1
  
  
    key     domain
    pattern .+
    tag     site.unmatched
  



  @type null

More Plugins

https://www.fluentd.org/plugins

fluentd不同输入插件区别和用法

1.in_tail插件

in_tail输入插件允许fluentd从text文件尾部读取事件,与tail -F命令相似.

Example Configuration

in_tail is included in Fluentd’s core. No additional installation process is required.


  @type tail  #required
  path /var/log/httpd-access.log  #required
  pos_file /var/log/td-agent/httpd-access.log.pos #记录td-agent重启前读取的的位置(强烈推荐)
  tag apache.access  #required
  format apache2

2.in_forward插件

in_forward输入插件监听一个 TCP socket接收事件流.也监听UDP socket 接收心跳消息.此插件主要用于从其他Fluentd实例,fluent-cat命令或客户端库接收事件日志。这是迄今为止检索记录的最有效方法。

注意: 如果没有安全连接,请勿将此插件用于DC间或公共互联网数据传输。为了提供可靠/低延迟的传输,我们假设此插件仅在专用网络中使用。 如果您打开此插件的端口到Internet,攻击者可以通过使用特定数据包轻松崩溃Fluentd。如果您需要节点之间的安全连接,请考虑使用in_secure_forward。

Example Configuration

in_forward is included in Fluentd’s core. No additional installation process is required.


  @type forward  #required
  port 24224
  bind 0.0.0.0

3.in_secure_forward插件

in_secure_forward输入插件通过SSL接受带有身份验证的消息.

in_secure_forward不包含在td-agent包或fluentd gem中。要安装它,请参阅https://docs.fluentd.org/v0.12/articles/plugin-management

Example Configuration

首先,通过secure-forward-ca-generate生成私有CA文件,然后通过安全方式(scp或其他方式)将该文件复制到输出插件端。


  @type secure_forward
  shared_key      secret_string
  self_hostname   server.fqdn.local  # This fqdn is used as CN (Common Name) of certificates
  secure true
  ca_cert_path        /path/to/certificate/ca_cert.pem
  ca_private_key_path /path/to/certificate/ca_key.pem
  ca_private_key_passphrase passphrase_for_private_CA_secret_key

4.in_udp插件

in_udp Input插件使Fluentd能够接受UDP有效负载。

Example Configuration

in_udp is included in Fluentd’s core. No additional installation process is required.


  @type udp
  tag mytag # required
  format /^(?\d+):(?\w+)$/ # required
  port 20001 # optional. 5160 by default
  bind 0.0.0.0 # optional. 0.0.0.0 by default
  body_size_limit 1MB # optional. 4096 bytes by default

5.in_tcp插件

in_tcp Input插件使Fluentd能够接受TCP有效负载。 不要使用此插件从客户端库接收日志。对这种情况使用in_forward。

Example Configuration

in_tcp is included in Fluentd’s core. No additional installation process is required.


  @type tcp
  tag tcp.events # required
  format /^(?\d+):(?\w+)$/ # required
  port 20001 # optional. 5170 by default
  bind 0.0.0.0 # optional. 0.0.0.0 by default
  delimiter \n # optional. \n (newline) by default

6.in_http插件

n_http Input插件使Fluentd能够从HTTP POST中检索记录。 URL路径成为Fluentd事件日志的标记,POSTed body元素成为记录本身。

Example Cofiguration

in_http is included in Fluentd’s core. No additional installation process is required.


  @type http
  port 8888
  bind 0.0.0.0
  body_size_limit 32m
  keepalive_timeout 10s

7.in_unix 插件

in_unix Input插件使Fluentd能够从Unix Domain Socket中检索记录。有线协议与in_forward相同,但传输层不同。

Example Configuration

in_unix is included in Fluentd’s core. No additional installation process is required.


  @type unix #required
  path /path/to/socket.sock #required

8.in_syslog插件

in_syslog输入插件使Fluentd能够通过UDP或TCP上的syslog协议检索记录。

Example Configuration

in_syslog is included in Fluentd’s core. No additional installation process is required.


  @type syslog
  port 5140
  bind 0.0.0.0
  tag system

9.in_exec插件

in_exec输入插件执行外部程序以接收或拉取事件日志。然后它将从程序的标准输出中读取TSV(制表符分隔值),JSON或MessagePack。 您可以定期或永久地运行程序。要定期运行,请使用run_interval参数。

Example Configuration

in_exec is included in Fluentd’s core. No additional installation process is required.


  @type exec #required
  command cmd arg arg #required
  keys k1,k2,k3
  tag_key k1
  time_key k2
  time_format %Y-%m-%d %H:%M:%S
  run_interval 10s

10.in_scribe插件

in_scribe输入插件使Fluentd能够通过Scribe协议检索记录。 Scribe是另一个由Facebook开源的日志收集器守护程序。 由于Scribe最近维护得不好,因此该插件对于希望将Fluentd与现有Scribe基础架构一起使用的现有Scribe用户非常有用。

install

in_scribe默认包含在td-agent中。Fluentd gem用户需要使用以下命令安装fluent-plugin-scribe gem:

$ fluent-gem install fluent-plugin-scribe

Example Configuration


  @type scribe
  port 1463

  bind 0.0.0.0
  msg_format json

11.in_multiprocess插件

默认情况下,Fluentd仅在系统上使用单个CPU核心。 in_multiprocess输入插件使Fluentd能够通过生成多个子进程来使用多个CPU核心。一个Fluentd用户使用此插件每天处理10亿条记录。

install

默认情况下,in_multiprocess不包含在td-agent中。 td-agent用户必须手动安装fluent-plugin-multiprocess。

  • Fluentd: fluent-gem install fluent-plugin-multiprocess
  • td-agent v2: /usr/sbin/td-agent-gem install fluent-plugin-multiprocess
  • td-agent v1: /usr/lib/fluent/ruby/bin/fluent-gem install fluent-plugin-multiprocess

Example Configuration


  @type multiprocess #required

   #required
    cmdline -c /etc/fluent/fluentd_child1.conf --log /var/log/fluent/fluentd_child1.log
    sleep_before_start 1s
    sleep_before_shutdown 5s
  
  
    cmdline -c /etc/fluent/fluentd_child2.conf --log /var/log/fluent/fluentd_child2.log
    sleep_before_start 1s
    sleep_before_shutdown 5s
  
  
    cmdline -c /etc/fluent/fluentd_child3.conf --log /var/log/fluent/fluentd_child3.log
    sleep_before_start 1s
    sleep_before_shutdown 5s
  

12.in_dummy插件

in_dummy输入插件生成虚拟事件。它对于Fluentd的测试,调试,基准测试和入门非常有用。

Example Configuration

in_dummy is included in Fluentd’s core. No additional installation process is required.


  @type dummy #required
  dummy {"hello":"world"} #required

fluentd不同输出插件区别和用法

1.out_file插件

out_file TimeSliced Output插件将事件写入文件。默认情况下,它每天创建文件(大约00:10)。这意味着当您首次使用插件导入记录时,不会立即创建任何文件。满足time_slice_format条件时将创建该文件。要更改输出频率,请修改time_slice_format值。

Example Configuration

out_file is included in Fluentd’s core. No additional installation process is required.


  @type file #required
  path /var/log/fluent/myapp #required
  time_slice_format %Y%m%d
  time_slice_wait 10m
  time_format %Y%m%dT%H%M%S%z
  compress gzip
  utc

2.out_s3插件

out_s3 TimeSliced Output插件将记录写入Amazon S3云对象存储服务。默认情况下,它每小时创建一次文件。这意味着当您首次使用插件导入记录时,不会立即创建任何文件。满足time_slice_format条件时将创建该文件。要更改输出频率,请修改time_slice_format值。

Installation

out_s3默认包含在td-agent中。fluentd gem用户需要使用以下命令安装fluent-plugin-s3 gem。

$ fluent-gem install fluent-plugin-s3

Example Configuration


  @type s3 #required

  aws_key_id YOUR_AWS_KEY_ID
  aws_sec_key YOUR_AWS_SECRET_KEY
  s3_bucket YOUR_S3_BUCKET_NAME
  s3_region ap-northeast-1
  path logs/
  buffer_path /var/log/fluent/s3

  time_slice_format %Y%m%d%H
  time_slice_wait 10m
  utc

  buffer_chunk_limit 256m

3.out_kafka插件

out_kafka输出插件将记录写入Apache Kafka。

Installation

在v2.3.3之后,out_kafka包含在td-agent2中。fluentd gem用户需要使用以下命令安装fluent-plugin-kafka gem。

$ fluent-gem install fluent-plugin-kafka

Example Configuration


  @type kafka_buffered #required

  # list of seed brokers
  brokers :,:

  # buffer settings
  buffer_type file
  buffer_path /var/log/td-agent/buffer/td
  flush_interval 3s

  # topic settings
  default_topic messages

  # data type settings
  output_data_type json
  compression_codec gzip

  # producer settings
  max_send_retries 1
  required_acks -1

4.out_forward插件

out_forward Buffered Output插件将事件转发给其他fluentd的节点。此插件支持负载平衡和自动故障转移(例如,主动 - 主动备份)。要进行复制,请使用out_copy插件。 out_forward插件使用“φaccrual failure detector”算法检测服务器故障。您可以自定义算法的参数。当服务器故障恢复时,插件会在几秒钟后自动使服务器可用。 out_forward插件支持最多一次和至少一次语义。默认值是最多一次。

Example Configuration

out_forward is included in Fluentd’s core. No additional installation process is required.


  @type forward
  send_timeout 60s
  recover_wait 10s
  hard_timeout 60s

  
    name myserver1
    host 192.168.1.3
    port 24224
    weight 60
  
  
    name myserver2
    host 192.168.1.4
    port 24224
    weight 60
  
  ...

  
    @type file
    path /var/log/fluent/forward-failed
  

5.out_secure_forward插件

out_secure_forward输出插件通过SSL通过身份验证发送消息.

Installation

out_secure_forward不包含在td-agent包或流利的gem中。要安装它,请参阅https://docs.fluentd.org/v0.12/articles/plugin-management

Example Configuration

首先,通过secure-forward-ca-generate在输入插件一侧生成私有CA文件,然后通过安全方式(scp或其他方式)将该文件复制到输出插件端。


  @type secure_forward
  shared_key secret_string
  self_hostname client.fqdn.local
  secure true
  ca_cert_path /path/to/certificate/ca_cert.pem

  
    host server.fqdn.local  # or IP
    # port 24284
  

注: 如果没有主机名ACL(尚未实现),则不会在任何状态下检查self_hostname。 “#{Socket.gethostname}”`占位符可用于此类情况。


  @type secure_forward
  shared_key secret_string
  self_hostname "#{Socket.gethostname}"
  secure true
  ca_cert_path /path/to/certificate/ca_cert.pem

  
    host server.fqdn.local  # or IP
    # port 24284
  

6.out_exec插件

out_exec TimeSliced Output插件将事件传递给外部程序。程序接收包含传入事件作为其最后一个参数的文件的路径。默认情况下,文件格式是制表符分隔值(TSV)。

Example Configuration

out_exec is included in Fluentd’s core. No additional installation process is required.


  @type exec
  command cmd arg arg
  format tsv
  keys k1,k2,k3
  tag_key k1
  time_key k2
  time_format %Y-%m-%d %H:%M:%S

7.out_exec_filter插件

out_exec_filter缓冲输出插件(1)使用事件作为输入执行外部程序,以及(2)从程序输出中读取新事件。它将制表符分隔值(TSV)传递给stdin,默认情况下从stdout读取TSV。

Example Configuration

out_exec_filter is included in Fluentd’s core. No additional installation process is required.


  @type exec_filter
  command cmd arg arg
  in_keys k1,k2,k3
  out_keys k1,k2,k3,k4
  tag_key k1
  time_key k2
  time_format %Y-%m-%d %H:%M:%S

8.copy插件

复制输出插件将事件复制到多个输出。

Example Configuration

out_copy is included in Fluentd’s core. No additional installation process is required.


  @type copy
  
    @type file
    path /var/log/fluent/myapp1
    ...
  
  
    ...
  
  
    ...
  

默认情况下,out_copy在store插件之间共享一条记录。 当deep_copy为true时,out_copy将不同的记录传递给每个store插件。

: 指定存储目标。格式与指令相同。

9.out_geoip插件

ut_geoip Buffered Output插件使用Maxmind GeoIP数据库将地理位置信息添加到日志中。

Prerequisites

The GeoIP library.

:::term # for RHEL/CentOS $ sudo yum install geoip-devel –enablerepo=epel

# for Ubuntu/Debian $ sudo apt-get install libgeoip-dev

# for MacOSX (brew) $ brew install geoip

Install

out_geoip不包含在td-agent中。所有用户必须使用以下命令安装fluent-plugin-geoip gem。

$ fluent-gem install fluent-plugin-geoip
$ sudo /usr/sbin/td-agent-gem install fluent-plugin-geoip

Example Configuration


  @type geoip
  geoip_lookup_key        host
  enable_key_country_code geoip_country
  enable_key_city         geoip_city
  enable_key_latitude     geoip_lat
  enable_key_longitude    geoip_lon
  remove_tag_prefix       test.
  add_tag_prefix          geoip.
  flush_interval          5s



:::text
# original record
test.message {
  "host":"66.102.9.80",
  "message":"test"
}

# output record
geoip.message: {
  "host":"66.102.9.80",
  "message":"test",
  "geoip_country":"US",
  "geoip_city":"Mountain View",
  "geoip_lat":37.4192008972168,
  "geoip_lon":-122.05740356445312
}

10.roundrobin插件

roundrobin Output插件使用循环算法将事件分配到多个输出。

Example Configuration

out_roundrobin is included in Fluentd’s core. No additional installation process is required.


  @type roundrobin

  
    @type tcp
    host 192.168.1.21
    ...
  
  
    ...
  
  
    ...
  

11.stdout插件

stdout输出插件将事件打印到stdout(如果使用守护程序模式启动,则打印日志)。此输出插件可用于调试目的。

Example Configuration

out_stdout is included in Fluentd’s core. No additional installation process is required.


  @type stdout

12.null插件

null输出插件只会丢弃事件。

Example Configuration

out_null` is included in Fluentd’s core. No additional installation process is required.


  @type null

13.out_webhdfs插件

out_webhdfs TimeSliced Output插件将记录写入HDFS(Hadoop分布式文件系统)。默认情况下,它每小时创建一次文件。这意味着当您首次使用插件导入记录时,不会立即创建任何文件。满足time_slice_format条件时将创建该文件。要更改输出频率,请修改time_slice_format值。

Install

out_webhdfs默认包含在td-agent中(v1.1.10或更高版本), fluentd gem用户必须使用以下命令安装fluent-plugin-webhdfs gem。

$ fluent-gem install fluent-plugin-webhdfs

HDFS Configuration

默认情况下,CDH上未启用追加操作。请将这些配置放入hdfs-site.xml文件并重新启动整个群集。

:CHD:Cloudera版本(Cloudera’s Distribution Including Apache Hadoop,简称“CDH”),基于Web的用户界面,支持大多数Hadoop组件,包括HDFS、MapReduce、Hive、Pig、 Hbase、Zookeeper、Sqoop,简化了大数据平台的安装、使用难度。


  dfs.webhdfs.enabled
  true



  dfs.support.append
  true



  dfs.support.broken.append
  true

Example Configuration


  @type webhdfs
  host namenode.your.cluster.local
  port 50070
  path "/path/on/hdfs/access.log.%Y%m%d_%H.#{Socket.gethostname}.log"
  flush_interval 10s

14.out_mongo插件

out_mongo Buffered Output插件将记录写入MongoDB,即面向文档的新兴数据库系统MongoDB。

Fluentd使您的应用程序可以通过批量插入异步插入MongoDB记录,而不像直接插入应用程序中的记录。这具有以下优点:

1.对应用程序性能影响较小

2.在维护JSON记录结构的同时提高MongoDB插入吞吐量

Install

out_mongo默认包含在td-agent中。fluentd gem用户需要使用以下命令安装fluent-plugin-mongo gem。

$ fluent-gem install fluent-plugin-mongo

Example Configuration

# Single MongoDB

  @type mongo
  host fluentd
  port 27017
  database fluentd
  collection test

  # for capped collection
  capped
  capped_size 1024m

  # authentication
  user michael
  password jordan

  # key name of timestamp
  time_key time

  # flush
  flush_interval 10s

15.out_mongo_replset插件

out_mongo_replset缓冲输出插件将记录写入MongoDB,即面向文档的新兴数据库系统MongoDB。

Install

out_mongo_replset默认包含在td-agent中, fluentd gem用户需要使用以下命令安装fluent-plugin-mongo gem。

$ fluent-gem install fluent-plugin-mongo

Example Configuration

# Single MongoDB

  @type mongo_replset
  database fluentd
  collection test
  nodes localhost:27017,localhost:27018,localhost:27019

  # flush
  flush_interval 10s

16.relable插件

relabel输出插件重新标记事件。

Example Configuration

out_relabel is included in Fluentd’s core. No additional installation process is required.


  @type relabel
  @label @foo



上面的示例将标签@foo放到匹配的事件中,label指令可以处理这些事件。 仅供参考:所有输入和输出插件也都有由Fluentd核心提供的@label参数。 relabel插件是一个实际上什么都不做的插件,但只支持@label参数。

17.out_rewrite_tag_filter插件

out_rewrite_tag_filter输出插件旨在重写像mod_rewrite这样的标记。当值与正则表达式匹配/不匹配时,使用重写标记重新发出记录。您还可以使用正则表达式按域,状态代码(例如500错误),用户代理,请求-URI,正则表达式反向引用等更改apache日志中的标记。

Install

out_rewrite_tag_filter默认包含在td-agent中(v1.1.18或更高版本)。fluentd gem用户必须使用以下命令安装fluent-plugin-rewrite-tag-filter gem。

$ fluent-gem install fluent-plugin-rewrite-tag-filter

Example Configuration

配置设计首先丢弃一些模式记录,然后重新发出其他匹配记录作为新标记名称。


  @type rewrite_tag_filter
  capitalize_regex_backreference yes
  
    key     path
    pattern \.(gif|jpe?g|png|pdf|zip)$
    tag     clear
  
  
    key     status #应用正则表达式的字段名称
    pattern ^200$ #正则表达式
    tag     clear #新标签
    invert  true  #如果为true,则在不匹配模式时重写标记
  
  
    key     domain
    pattern ^.+\.com$
    tag     clear
    invert  true
  
  
    key     domain
    pattern ^maps\.example\.com$
    tag     site.ExampleMaps
  
  
    key     domain
    pattern ^news\.example\.com$
    tag     site.ExampleNews
  
  # it is also supported regexp back reference.
  
    key     domain
    pattern ^(mail)\.(example)\.com$

 - [ ] List item

    tag     site.$2$1
  
  
    key     domain
    pattern .+
    tag     site.unmatched
  



  @type null

More Plugins

https://www.fluentd.org/plugins

你可能感兴趣的:(fluentd)