elasticsearch - Fluentd 尾源不将日志移动到 ElasticSearch

标签 elasticsearch fluentd

我正在尝试使用 Fluentd 尾源将我的 Python 日志文件移动到 ElastiSearch 中:

<source>
  @type  forward
  @id    input1
  @label @mainstream
  port  24224
</source>

<filter **>
  @type stdout
</filter>

<source>
  @type tail
  path /fluentd/formshare/error_log
  pos_file /fluentd/error_log.pos
  tag formshare.error
  <parse>
    @type multiline
    format_firstline /\d{4}-\d{1,2}-\d{1,2}/
    format1 /(?<timestamp>[^ ]* [^ ]*) (?<level>[^\s]+:)(?<message>[\s\S]*)/
  </parse>
</source>

<label @mainstream>
  <match formshare.access.**>
    @type elasticsearch
    host 172.28.1.1
    port 9200
    logstash_format true
    logstash_prefix formshare_access
  </match>
  <match formshare.error.**>
    @type elasticsearch
    host 172.28.1.1
    port 9200
    logstash_format true
    logstash_prefix formshare_error
  </match>
  <match **>
    @type file
    @id   output1
    path         /fluentd/log/data.*.log
    symlink_path /fluentd/log/data.log
    append       true
    time_slice_format %Y%m%d
    time_slice_wait   10m
    time_format       %Y%m%dT%H%M%S%z
  </match>
</label>

我可以通过启动正在解析文件的 FluentD 服务看到:

following tail of /fluentd/formshare/error_log



并且 pos_file 有数据
/fluentd/formshare/error_log    0000000000000604        000000000098252c

但我没有得到 ElasticSearch 中的错误。它可能是解析的,但我不擅长正则表达式(从 https://www.datadoghq.com/blog/multiline-logging-guide/ 获得)

与 Elastic 的连接正常。我与“fluent-logger-python”一起使用的匹配 formshare.access.** 工作正常。只是似乎不起作用的尾源。

我是 Fluentd 的 super 新手,所以我不知道我是否以正确的方式做事,或者我是否需要配置文件中的其他内容。

任何帮助表示赞赏。

最佳答案

经过一些试验和错误,我得到了它与这个conf文件一起工作:

<source>
  @type  forward
  @id    input1
  @label @mainstream
  port  24224
</source>

<filter **>
  @type stdout
</filter>

<source>
  @type tail
  @label @mainstream
  @id    input2
  path /fluentd/formshare/error_log
  pos_file /fluentd/error_log.pos
  tag formshare.error
  <parse>
    @type multiline
    format_firstline /\d{4}-\d{1,2}-\d{1,2}/
    format1 /(?<time>\d{4}-\d{1,2}-\d{1,2} +\d{1,2}:\d{1,2}:\d{1,2},\d{3}) +(?<level>[A-Z]+)[ ]{1,2}\[(?<module>(.*?))\]\[(?<thread>(.*?))\] (?<messages>.*)/
    time_format %Y-%m-%d %H:%M:%S,%L
  </parse>
</source>

<label @mainstream>
  <match formshare.access.**>
    @type elasticsearch
    host 172.28.1.1
    port 9200
    logstash_format true
    logstash_prefix formshare_access
    time_key_format %Y.%m.%d
  </match>
  <match formshare.error.**>
    @type elasticsearch
    host 172.28.1.1
    port 9200
    logstash_format true
    logstash_prefix formshare_error
    time_key_format %Y.%m.%d
  </match>
  <match **>
    @type file
    @id   output1
    path         /fluentd/log/data.*.log
    symlink_path /fluentd/log/data.log
    append       true
    time_slice_format %Y%m%d
    time_slice_wait   10m
    time_format       %Y%m%dT%H%M%S%z
  </match>
</label>

我遇到的问题:
  • 两个来源必须具有相同的@label 和不同的@id
  • 正则表达式对于我的 Python 日志文件不正确。
  • Fluentd on start 计算文件的尾部但不处理它。如果文件是空的并且你用数据覆盖它,Fluentd 处理这些行。
  • 关于elasticsearch - Fluentd 尾源不将日志移动到 ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58273084/

    相关文章:

    fluentd - 通过fluentD限制相同日志的条数

    logging - 在FluentD中解析内部JSON

    kubernetes - 如何通过fluentd将json日志发送到stackdriver

    Elasticsearch 使用关键字术语进行 KNN 搜索

    elasticsearch - Elastic Search使用多个索引和路由

    python - Elasticsearch Shape 查询以从嵌套 JSON 中查找边界多边形和背景颜色(Google OCR 响应)

    docker - kubernetes 中的多行 Fluentd 日志

    config - Fluentd 配置文件,在 <source> 中获取文件名并将其作为标记传递给 <match>

    Elasticsearch 何时重新索引?

    elasticsearch - logstash 5.0.1 : setup elasticsearch multiple indexes ouput for multiple kafka input topics