tail

in_tail输入插件从文本文件的尾部读取事件,类似于linux中的tail -F命令。
格式如下

  1. <source>
  2. @type tail
  3. path /var/log/httpd-access.log
  4. pos_file /var/log/td-agent/httpd-access.log.pos
  5. tag apache.access
  6. <parse>
  7. @type apache2
  8. </parse>
  9. </source>

eg:
在当前目录下创建etc目录和 fluent.conf配置文件

  1. $mkdir etc
  2. $vim etc/fluent.conf

如下配置内容

  1. <source>
  2. @type tail
  3. path /tmp/test.log
  4. pos_file /tmp/test.log.pos
  5. tag test.log
  6. <parse>
  7. @type none
  8. </parse>
  9. </source>
  10. <match test.log>
  11. @type copy
  12. <store>
  13. @type stdout
  14. </store>
  15. <store>
  16. @type file
  17. path /tmp/test_backup/
  18. </store>
  19. </match>

创建docker

  1. $ docker run -d --name fluentd -v $(pwd)/etc:/fluentd/etc -v $(pwd)/tmp:/tmp fluent/fluentd
  1. $ docker logs fluentd
  2. 2020-08-10 17:18:31.047687752 +0000 test.log: {"message":"hell world"}

查看备份文件

  1. $ ls -ll ./tmp/test_backup/
  2. total 16
  3. -rw-r--r-- 1 baxiang staff 60 Aug 11 01:18 buffer.b5ac8924c6a3a1895406e4b7058a1db0c.log
  4. -rw-r--r-- 1 baxiang staff 68 Aug 11 01:18 buffer.b5ac8924c6a3a1895406e4b7058a1db0c.log.meta

查看备份文件内容

  1. $ cat ./tmp/test_backup/buffer.b5ac8924c6a3a1895406e4b7058a1db0c.log
  2. 2020-08-10T17:18:31+00:00 test.log {"message":"hell world"}

in_forward

in_forward插件通常用于从其他节点接收日志事件,这些节点包括其他Fluentd实例、fluent-cat命令行或者Fluentd客户端程序。这是目前效率最高的日志事件接收方法。
in_forward插件会在本地打开一个tcp监听socket,用于接收日志事件。同时,它也会开启一个udp端口用于接收和对端的心跳保活消息。
in_forward可接收json或MessagePack格式的数据,它会自动探测源数据是哪种格式。MessagePack是Fluentd内部使用的数据封装格式,因其效率高于json。
in_forward插件内置于Fluentd,无须安装。

  1. <source>
  2. @type forward
  3. port 24224
  4. bind 0.0.0.0
  5. </source>

in_http

in_http插件允许使用HTTP协议来采集日志事件。这个插件会建立一个支持REST风格的HTTP端点,来接收日志事件请求。

参考

https://docs.fluentd.org/input