问题描述
我在Google网上论坛中发布了此问题,但找不到最佳解决方案。 我的配置中有两个问题。
- 我无法将正则表达式传递给grep过滤器。它始终被替换为null。
- 我不使用地图过滤器,因为它的存在会使日志不再转发。
请参见以下代码段。
<match fluent.**>
@type null
</match>
<source>
@type tail
@id in_tail_abc_container_logs_dd
path "/var/log/containers/abc-*.log"
pos_file "/var/log/abc-fluentd-containers-dd.pos"
tag "datadog"
read_from_head true
emit_unmatched_lines false
<parse>
@type "json"
time_format "%Y-%m-%dT%H:%M:%s.%NZ"
unmatched_lines false
time_type string
</parse>
</source>
<source>
@type tail
@id in_tail_abc_container_logs_es
path "/var/log/containers/abc-*.log"
pos_file "/var/log/abc-fluentd-containers-es.pos"
tag "es"
read_from_head true
emit_unmatched_lines false
<parse>
@type "json"
time_format "%Y-%m-%dT%H:%M:%s.%NZ"
unmatched_lines false
time_type string
</parse>
</source>
<filter datadog.**>
@type grep
<regexp>
key "log"
pattern "#{ENV['FILTER_REGEX'] || '/(\s|^|[[:punct:]])(error|fail|Failed|critical|fatal)/i' }"
</regexp>
</filter>
<filter es>
@type map
time "time"
record "(record[\"log\"])"
</filter>
<match datadog.**>
@type datadog
@id dcs_datadog_agent
api_key "#{ENV['DD_API_KEY']}"
# Optional
#include_tag_key false
#tag_key 'tag'
# Optional tags
# dd_source "#{ENV['DD_INTEGRATION_SOURCE']}"
# dd_tags "#{ENV['DD_TAGS_KEY_VALUES']}"
<buffer>
@type memory
flush_thread_count 4
flush_interval 3s
chunk_limit_size 5m
chunk_limit_records 500
</buffer>
</match>
<match es.**>
@type "aws-elasticsearch-service"
type_name "access_log"
logstash_format true
include_tag_key true
tag_key "@log_name"
flush_interval 1s
logstash_prefix "#{ENV['FLUENT_ELASTICSEARCH_LOGSTASH_PREFIX'] || 'dcs'}"
<endpoint>
url "#{ENV['AWS_ES_CLUSTER_ENDPOINT']}"
region "#{ENV['AWS_ES_CLUSTER_REGION']}"
access_key_id "#{ENV['AWS_ES_USER_ACCESS_KEY']}"
secret_access_key "#{ENV['AWS_ES_USER_SECRET_KEY']}"
</endpoint>
</match>
数字1:
我无法按照以下建议仅提取日志条目
<filter es>
@type map
time "time"
record "(record[\"log\"])"
</filter>
在https://groups.google.com/g/fluentd/c/qLuRtRkm4V0?pli=1上查看讨论
另一部分是我无法以任何形式将正则表达式传递给以下内容。 在我发送的任何格式中,它仅作为null出现。我尝试发送正常的字符串,如错误,但也没有出现。详细信息如下。
<filter datadog.**>
@type grep
<regexp>
key "log"
pattern "#{ENV['FILTER_REGEX] || '/(\s|^|[[:punct:]])(error|fail|Failed|critical|fatal)/i' }"
</regexp>
</filter>
,因此的输出始终为空。环境变量设置好,我已经检查了相同。并且以相同配置传递的其他参数运行良好,例如aws access和secret作为参数传递。
我尝试了另一种不同的方法,但是每当使用关键字模式时,参数化都无效。
以下内容也不起作用,因为替换的值为null
<match datadog.**>
@type rewrite_tag_filter
<rule>
key log
pattern "#{ENV['FILTER_REGEX'] || '/(\s|^|[[:punct:]])(error|fail|Failed|critical|fatal)/i' }"
tag error
</rule>
</match>
fluend在kubernetes集群中作为docker运行,代码类似于下面的链接 https://github.com/fluent/fluentd-kubernetes-daemonset/tree/master/docker-image/v1.9/debian-elasticsearch7
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)