4、fluentd之配置文件的格式

source

"source": where all the data come from

source:就是输入源(input),比较常用的有两个插件一个是http,一个是forward(tcp)
其它的插件,可以去官网查找

# Receive events from 24224/tcp
# This is used by log forwarding and the fluent-cat command
<source>
  @type forward  # 这个就是表示插件
  port 24224
</source>

# http://this.host:9880/myapp.access?json={"event":"data"}
<source>
  @type http
  port 9880
</source>

match

"match": Tell fluentd what to do

match:指定输出的目的(output)

# Receive events from 24224/tcp
# This is used by log forwarding and the fluent-cat command
<source>
  @type forward
  port 24224
</source>

# http://this.host:9880/myapp.access?json={"event":"data"}
<source>
  @type http
  port 9880
</source>

# Match events tagged with "myapp.access" and
# store them to /var/log/fluent/access.%Y-%m-%d
# Of course, you can control how you partition your data
# with the time_slice_format option.
<match myapp.access> 
  @type file   # 这个就是output插件
  path /var/log/fluent/access
</match>

filter

"filter": Event processing pipeline

filter:可以理解为过滤器

流程如下:

Input -> filter 1 -> ... -> filter N -> Output

如下为record_transformerfilter插件实例

# http://this.host:9880/myapp.access?json={"event":"data"}
<source>
  @type http
  port 9880
</source>

<filter myapp.access>
  @type record_transformer
  <record>
    host_param "#{Socket.gethostname}"
  </record>
</filter>

<match myapp.access>
  @type file
  path /var/log/fluent/access
</match>

label

就是为了降低tag过滤的复杂性

<source>
  @type forward
</source>

<source>
  @type tail
  @label @SYSTEM   # 这个input 直接进到label 哪里进行处理
</source>

<filter access.**>
  @type record_transformer
  <record>
    # ...
  </record>
</filter>
<match **>
  @type elasticsearch
  # ...
</match>

<label @SYSTEM>
  <filter var.log.middleware.**>
    @type grep
    # ...
  </filter>
  <match **>
    @type s3
    # ...
  </match>
</label>

system

主要设置一些系统配置的

  • log_level
  • suppress_repeated_stacktrace
  • emit_error_log_interval
  • suppress_config_dump
  • without_source
  • process_name (only available in system directive. No fluentd
    option)

在td-agent.conf文件中添加如下

<system>
  process_name fluentd1
</system>
% ps aux | grep fluentd1
foo      45673   0.4  0.2  2523252  38620 s001  S+    7:04AM   0:00.44 worker:fluentd1
foo      45647   0.0  0.1  2481260  23700 s001  S+    7:04AM   0:00.40 supervisor:fluentd1

include

就是导入

第一步:先编写source.conf

<source>
  @type http
  port 8887
  bind 0.0.0.0
</source>

第二步:编写td-agent.conf文件

@include ./source.conf  # 这一步:就会将上面的内容导入到这里
<filter test.cycle>
  @type grep
  <exclude>
    key action
    pattern ^login$
  </exclude>
</filter>

<label @STAGING>
  <filter test.cycle>
    @type grep
    <exclude>
      key action
      pattern ^logout$
    </exclude>
  </filter>

  <match test.cycle>
    @type stdout
  </match>
</label>

<match test.cycle>
  @type stdout
</match>

通配符

filter 和 match 标签中的tag 通配符号

  • *:匹配满足一个tag部分的事件, 比如: a.*, 它将匹配a.b这样的tag, 但是不会处理a或者a.b.c这类tag
  • **:匹配满足0个或多个tag部分,比如: a.**, 它将匹配a, a.b, a.b.c这三种tag
  • {X,Y,Z}:匹配满足X,Y或者Z的tag, 比如: {a, b}将匹配a或者b,但是不会匹配c。这种格式也可以和通配符组合使用,比如a.{b.c}.*或a.{b.c}.*
  • #{...}:会将里面的内容当作ruby表达式处理:比如
<match "app.#{ENV['FLUENTD_TAG']}">
  @type stdout
</match>

如果设置了环境变量FLUENTD_TAGdev,那上面等价于app.dev

  • 当指定了多个模式时(使用一个或多个空格分开),只要满足其中任意一个就行.比如:
    <match a b>匹配a和b
    <match a.** b.*>匹配a, a.b, a.b.c, b.d等

配置文件中的参数类型

每个Fluentd插件都有一组参数。例如,in_tail具有rotate_wait和pos_file等参数。每个参数都有一个与之关联的特定类型。它们的定义如下:

  • string:字符串,最常见的格式,详细支持语法见文档[^literal];

  • integer:整数

  • float:浮点数;

  • size大小,仅支持整数

  • <INTEGER>k<INTERGER>K

  • <INTEGER>m<INTERGER>M

  • <INTEGER>g<INTERGER>G

  • <INTEGER>t<INTERGER>T

  • time :时间,也只支持整数;

    • <INTEGER>s<INTERGER>S
    • <INTEGER>m<INTERGER>M
    • <INTEGER>h<INTERGER>H
    • <INTEGER>d<INTERGER>D
  • array:按照 JSON array 解析
    完整格式的写法: ["key1", "key2"]
    简写: key1,key2

  • hash:按照 JSON object 解析
    完整格式的写法:{"key1":"value1", "key2":"value2"}
    简写:key1:value1,key2:value2

多个match之间的顺序

当有多个match, 需要注意一下它们的顺序, 如下面的例子,第二个match永远也不会生效

# ** matches all tags. Bad :(
<match **>
  @type blackhole_plugin
</match>

<match myapp.access>
  @type file
  path /var/log/fluent/access
</match>

如果将filter放在match之后,那么它也永远不会生效,正确的用法如下:

# You should NOT put this <filter> block after the <match> block below.
# If you do, Fluentd will just emit events without applying the filter.
<filter myapp.access>
  @type record_transformer
  ...
</filter>

<match myapp.access>
  @type file
  path /var/log/fluent/access
</match>

检查配置文件是否可用

fluentd --dry-run -c fluent.conf
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
fluentd配置包括通过设置启动选项或配置文件进行的设置。在启动时,可以设置log_level、suppress_repeated_stacktrace、emit_error_log_interval、suppress_config_dump和without_source等选项。配置文件由多个指令组成,包括source、match、filter、system、label和@include等指令。其中,source指令确定输入源,match指令确定输出目的地,filter指令确定事件处理管道,system指令设置系统级配置,label指令将output和filter分组以进行内部路由,@include指令用于包括其他文件。配置示例中,首先定义了source,表示数据的来源,然后通过filter指令将处理串成管道,形成一个事件流。具体来说,事件流的顺序是Input -> filter 1 -> ... -> filter N -> Output。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Fluentd 配置](https://blog.csdn.net/hxpjava1/article/details/79447630)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Fluentd配置](https://blog.csdn.net/koalazoo/article/details/84770595)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值