fluentd学习——配置文件Config File(关键)

配置文件Config File(关键) 

 http://docs.fluentd.org/articles/config-file

Overview 

概述

The configuration file allows the user to control the input and output behavior of Fluentd by (1) selecting input and output plugins and (2) specifying the plugin parameters. The file is required for Fluentd to operate properly.

配置文件允许用户控制Fluentd的输入和输出行为,通过(1)选择输入和输出插件(2)指定插件的参数。Fluentd的正常运作,这个配置文件是必须的。

Config File Location

配置文件位置

RPM or Deb

If you installed Fluentd using the rpm or deb packages, the config file is located at /etc/td-agent/td-agent.conf. sudo /etc/init.d/td-agent reload will reload the config file.

如果你安装Fluentd运用的是rpm或是deb 的安装包,这个配置文件在/etc/td-agent/td-agent.conf 这个目录。重新安装将会安装conf 配置文件。

$ sudo vi /etc/td-agent/td-agent.conf

Gem

If you installed Fluentd using the Ruby Gem, you can create the configuration file using the following commands. Sending a SIGHUP signal will reload the config file.

如果你安装Fluentd 用的是Ruby Gem,你可以创建一个配置文件运用下面的命令。发出一个终止信号将会重新安装配置文件。(如果你修改了配置文件—fluent.conf 文件,ctrl c c 终止进程,然后在配置文件下重新启动)

$ ctrl c 

$fluentd -c fluent.conf

$ sudo fluentd --setup /etc/fluent
$ sudo vi /etc/fluent/fluent.conf

List of Directives

指令列表

The configuration file consists of the following directives:

这个配置文件由以下指令组成:

  1. source directives determine the input sources.
  2. match directives determine the output destinations.
  3. include directives include other files.
     1.  source  指令决定输入资源。
     2.  match  指令决定输出目的地。
     3.   include  指令包含其他一些文件

(1) Source Directive

source 指令

Fluentd’s input sources are enabled by selecting and configuring the desired input plugins using source directives. Fluentd’s standard input plugins include http and forward.

Fluentd 的输入源是通过选择和配置所需要的输入插件使用source指令。Fluentd的标准输入插件包含httpforward转发模式


Examples

# Receive events from 24224/tcp #从24224/tcp 中接收事件,tcp模式
# This is used by log forwarding and the fluent-cat command #使用日志转发和fluent-cat 命令

  type forward
  port 24224


# http://this.host:9880/myapp.access?json={"event":"data"} 

  type http
  port 9880

Each source directive must include a type parameter. The type parameter specifies the input plugin to use.

每个 source指令必须包含一个 type(类型)参数。 type参数指定 输入插件使用。

Routing

选择路径

The ‘source’ submits events into the Fluentd’s routing engine. An event consists of three entities: tagtime and record. The tag is a string separated by ‘.’s (e.g. myapp.access), and is used as the directions for Fluentd’s internal routing engine. The time is the UNIX time when the event occurs. The record is a JSON object.

source 把事件提交到fluentd的路由引擎中。一个事件包含三个实体标签:tag,time和record。tag是一个通过 . 来分离的字符串 (e.g. myapp.access),用作Fluentd内部路由引擎的方向。time是当事件产生unix时间。record是一个JSON对象。

(主要的是tag,用来指导方向,所要匹配的地方)

In the example above, the HTTP input plugin submits the following event::

在上面的例子中,HTTP输入插件提交以下事件:

# generated by http://this.host:9880/myapp.access?json={"event":"data"}
tag: myapp.access
time: (current time)
record: {"event":"data"}

Plugin

插件

Users can expand Fluentd’s input sources beyond the default options by writing their own plugins. For further information regarding Fluentd’s input sources, please refer to the Input Plugin Overview article.

用户可以扩展输入源Fluentd,通过编写自己的插件而超出默认选项。为了进一步关于fluentd 的信息,请参考 Input Plugin Overview 文章。(怎样修改fluentd的默认插件的内容,就是修改fluent.conf文件)

(2) Match Directive

match指令(仔细看)

Fluentd’s output destinations are enabled by selecting and configuring the desired output plugins using match directives. Fluentd’s standard output plugins include file and forward.

Fluentd 的 输出的目的地是通过 选择和配置所需的 输出插件使用 match的指令。Fluentd的标准输出插件包含 fileforward

Fluentd 的输入源是通过选择和配置所需要的输入插件使用source指令。Fluentd的标准输入插件包含httpforward转发模式

Examples

# Match events tagged with "myapp.access" and   match 事件是为了匹配  tag myapp.access和 这就是为什么
# store them to /var/log/fluent/access.%Y-%m-%d

  type file
  path /var/log/fluent/access



  type file
  format /var/log/fluent/myapp_hourly
  time_slice_format %Y%m%d%H

Each match directive must include a match pattern and a type parameter. Match patterns are used to filter the events. Only events with tag matching the pattern will be sent to the output destination. The type parameter specifies the output plugin to use.

每个 match指令必须包括一个 匹配模式type参数。match模式是用来过滤事件。只有 事件与tag匹配,这个模式将被发送到输出目的地。 type参数指定 输出插件使用。

For example, the user can send all matches to the pattern myapp.accesslog.** to file in a specified directory.

例如,用户可以发送所有匹配 myapp.accesslog.* *的模式到指定的目录 file

Users can expand Fluentd’s output sources beyond the default options by writing their own plugins. For further information regarding Fluentd’s output destinations, please refer to the Output Plugin Overview article.

用户可以通过编写自己的插件,覆盖默认选项,来扩大Fluentd的输出源。为进一步的信息关于Fluentd的输出目的地,请参考   Output Plugin Overview 文章。

Match Pattern

match 模式

The following match patterns can be used:

  • * matches a single tag element. 匹配单个tag元素 a.* = a.b 不等于 a.b.c

    • For example, the pattern a.* matches a.b, but does not match a or a.b.c

** matches zero or more tag elements.  a.**=aa.b 和a.b.c

  • For example, the pattern a.** matches aa.b and a.b.c
  • {X,Y,Z} matches X, Y, or Z, where X, Y, and Z are match patterns.

    • For example, the pattern {a,b} matches a and b, but does not match c。{a,b} 匹配 a and b,但不匹配 c

    • This can be used in combination with the * or ** patterns. Examples include a.{b,c}.* and a.{b,c.**}

(3) Include Directive

包含指令

Directives in separate configuration files can be imported using the include directive::

指令在单独的配置文件可以导入使用 include 指令::

# Include config files in the ./config.d directory
include config.d/*.conf

The include directive supports regular file path, glob pattern, and http URL conventions::

include 指令支持常规路径,glob模式和http约定::

# absolute path  绝对路径
include /path/to/config.conf

# if using a relative path, the directive will use 
# the dirname of this config file to expand the path
如果使用性对路径,这个配置文件的目录名将使用扩张后的路径命令。
include extra.conf

# glob match pattern
include config.d/*.conf

# http
include http://example.com/fluent.conf

你可能感兴趣的:(CloudFoundry)