[英]Fluentd grep + output logs
我有一个服务,已部署到kubernetes集群中,并且将fluentd设置为守护程序集。 而且我需要使收到的日志多样化,以便它们最终位于不同的s3存储桶中。 一个存储桶将用于由kubernetes和我们的调试/错误处理代码生成的所有日志,而另一个存储桶将是由服务生成,由结构化记录器解析并由json中的特定字段标识的日志的子集。 可以想象一下,一个存储桶是针对机器状态和错误的,而另一个存储桶是针对“用户操作的ts中创建的user_id创建的资源image_id”
服务本身并不了解fluentd,因此我无法根据我希望它们结尾的s3存储桶手动设置日志标签。现在,fluentd.conf我使用如下设置s3的东西:
<match **>
# docs: https://docs.fluentd.org/v0.12/articles/out_s3
# note: this configuration relies on the nodes have an IAM instance profile with access to your S3 bucket
type copy
<store>
type s3
log_level info
s3_bucket "#{ENV['S3_BUCKET_NAME']}"
s3_region "#{ENV['S3_BUCKET_REGION']}"
aws_key_id "#{ENV['AWS_ACCESS_KEY_ID']}"
aws_sec_key "#{ENV['AWS_SECRET_ACCESS_KEY']}"
s3_object_key_format %{path}%{time_slice}/cluster-log-%{index}.%{file_extension}
format json
time_slice_format %Y/%m/%d
time_slice_wait 1m
flush_interval 10m
utc
include_time_key true
include_tag_key true
buffer_chunk_limit 128m
buffer_path /var/log/fluentd-buffers/s3.buffer
</store>
<store>
...
</store>
</match>
所以,我想做的就是拥有grep插件之类的东西
<store>
type grep
<regexp>
key type
pattern client-action
</regexp>
</store>
它将日志发送到单独的s3存储桶中,该存储桶是为所有日志定义的存储桶
我假设用户操作日志是由您的服务生成的,而系统日志包括来自节点的docker,kubernetes和systemd日志。 我在官方流利的github repo上找到了您的示例yaml文件。 如果您在该链接中检出该文件夹,则会看到另外两个名为kubernetes.conf
和systemd.conf
文件。 这些文件具有source
部分,在其中tag
了数据。
fluent.conf中的match
部分匹配**
,即所有日志并将其发送到s3。 您要在此处拆分日志类型。 您的容器日志在此行的kubernetes.conf中被标记为kubernetes.*
。
所以你上面的配置变成
<match kubernetes.* >
@type s3
# user log s3 bucket
...
对于系统日志,除kubernetes之外,其他所有标签均match
。*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.