Fluentd 一些插件的使用
geoip 的配置模版
- <filter request>
- @type geoip
- geoip_lookup_keys ip
- backend_library geoip_c
- geoip2_database /Fluentd/plugin/GeoLite2-City.mmdb
- geoip2_database /Fluentd/plugin/GeoLiteCity.dat
- <record>
- location '[${location.latitude["ip"]},${location.longitude["ip"]}]'
- </record>
- </filter>
健康日志的过滤模版
- <filter request>
- @type grep
- <exclude>
- key message
- pattern /.*healthcheck.*|.*prometheusMetrics.*|.*(v1+\/)+(configurations)+(\/+versions).*/
- </exclude>
- </filter>
删除某些字段
- <filter *>
- @type record_transformer remove_keys message
- </filter>
Fluentd 优化的问题.
1. 有日志有些会丢失,
- path /log-dir/*-App.log
- pos_file /log-dir/App.log.pos
多个日志文件的位置记录写入一个位置记录文件, 会导致日志位置记录的错误, 想的办法: 为每个日志文件单独配置一个位置记录的文件.
- path /log-dir/*-App.log
- pos_file ${path}.ops
想通过引用的方式来为每个 path 创建一个 ops, 但是结局不生效通过仔细阅读官方文档, 发现一个 in_tail 进程里的 ops 是可以存放多个 path
2. 日志会在一分钟后传输到 ES 上
我把日志写入 docker 日志文件, 发现 Fluentd 处理读取和处理速度并不慢, 猜测可能是 Fluentd 传输到 ES 过程中的问题.
通过在在 match 输出上面刷新缓冲区, 及时把缓冲区的数据送到 ES,
- <match App.*>
- @type Elasticsearch host elasticsearchlog-lb.Elasticsearch-log index_name
- s3-Fluentd-idaas type_name s3-Fluentd-idaas flush_interval 2s include_timestamp
- true ssl_verify false
- </match>
第二个方法就是找到冲突的地方删除掉冲突点 (仅仅是个想法)
3.Fluentd 报警刷屏
id 和 key 都没问题, 因为昨天晚上我从 S3 上拉取下来过,
今天 s3 的桶里面加上了路径
Amazon S3 logstash-idaas/2018/10/20/
容器日志报出的错误
error_class=AWS::S3::Errors::NoSuchKey error="The specified key does not exist."
(1) 测试没有前缀的时候是否会报错
结局: 报错少了一些, 但是还是会报错
(2) 排错过程:
1. 我想看看 logstash 中 S3 插件是否会给我产生灵感 否
2. 我想测试 Fluentd 中是否有插件导致了这个问题 否
通过把原有插件卸载, 使用最简插件方案来运行这个配置文件
3.Google 搜索看看 否
4.SQS 队列里含有各桶的数据, 相互之间冲突, 新建一个 SQS 解决这个问题 nice
测试出来的原因就是 SQS 处理多个 S3 桶数据的时候, 每个桶之间的数据会相互杂糅, 促使 Fluentd 拉去数据的时候前缀路径冲突, 这个时候我们每一个桶分配一个 SQS 解决这个问题
4. 这个队列无法访问
2018/11/12 上午 11:52:552018-11-12 11:52:55 +0800 [error]: #0 unexpected error error_class=AWS::SQS::Errors::NonExistentQueue error="The specified queue does not exist or you do not have access to it
检查队列名字和 SQS 的权限配置, 还有需要检查 S3 桶的事件通知
5. 报出一个错误
2018/11/15 下午 7:00:222018-11-15 19:00:22 +0800 [warn]: #0 dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error="400 - Rejected by Elasticsearch" location=nil tag="app.idaas"
通过观看, 发现这个问题主要是 App.idaas 标签产生的, 因为这个标签没有 filter, 后来对 App.idaas 进行一次 filter 后, 这个警告问题可以大大缓解.
- <filter App.idaas>
- @type parser
- key_name thread_name
- reserve_data yes
- <parse>
- @type regexp
- expression /(?<thread_name>[\d\D]+)/
- </parse>
- </filter>
6.ES 报出的错误
2018/11/16 下午 4:16:072018-11-16 16:16:07 +0800 [warn]: #0 Could not push logs to Elasticsearch, resetting connection and trying again. read timeout reached
2018-11-16 16:16:44 +0800 [warn]: #0 buffer flush took longer time than slow_flush_log_threshold: elapsed_time=66.07182049937546 slow_flush_log_threshold=20.0 plugin_id="object:2ac85a0bd4a0"
去除下面 buffer 中的 timekey 和 timekey_wait
- index_name s3-Fluentd-request-%Y%m%d
- <buffer tag,time>
- timekey 4s
- timekey_wait 1s
- </buffer>
Fluentd 日志处理 - 安装配置 (一)
http://blog.51cto.com/11078047/2316881
Fluentd 日志处理 - S3 拉取日志处理 (二)
http://blog.51cto.com/11078047/2316910
Fluentd 日志处理 - tail 拉取 (三)
http://blog.51cto.com/11078047/2316958
来源: http://www.bubuko.com/infodetail-2855530.html