Fluentd日志处理-插件使用和调试问题(四)

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>

猜你喜欢

转载自blog.51cto.com/11078047/2320018