我正在尝试使用 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>
我遇到的问题:
关于elasticsearch - Fluentd 尾源不将日志移动到 ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58273084/