zoukankan      html  css  js  c++  java
  • ELK~fluentd多行日志的收集

    事实上,在sidecar里使用fluentd来收集日志是非常不错的选择,通过对日志文件的监控,将文件定时发到ES里,通过kibana去读取;而你的日志如果使用tail的话,默认是一行一行读取的,这对于多行信息的日志,是非常不友好的,所以今天写一个多行日志读取的方法。
    sidecar就是k8s里为pod提供的一个插件,类似于给摩托车加一个连斗,所以又叫连斗模式,即一个pod包含了两个容器,一个是主程序,一个是fluentd程序,如图:
    2

    需要用正则

    我们在使用时,需要注册,这个多行需要有正则匹配的,这取决于你的日志输出格式,今天我写的日志格式如下:

    2020-09-25 16:55:29.555 [XNIO-1 task-1] INFO : hello world!
    

    针对于上面的日志格式,我们的fluentd的配置如下

       <source>
          type tail
          path /var/log/*.log 
          pos_file /var/log/*.log.pos
          tag test
          refresh_interval 120
          format multiline
          multiline_flush_interval 5s
          format_firstline /d{4}-d{1,2}-d{1,2}/
          format1 /^(?<access_time>d{4}-d{2}-d{2} d{2}:d{2}:d{2}.d{3}) [(?<thread>.*)] (?<level>[^ ]*) (?<message>.*)/
        </source>
        <match **>
          @id elasticsearch
          @type elasticsearch
          index_name fluentd
          type_name _doc
          host 192.168.60.136
          port 9200
          include_tag_key true
          tag_key @log_name
          logstash_format true
          flush_interval 10s
          logstash_prefix test
        </match>
    

    需要注意的事,由于使用到了多行文本的收集,所以你的fluentd客户端需要安装对应的插件,我们这边用的是docker方式,插件已经装好了。
    1
    这个技术我研究和尝试了很多次,最后还是成功了!
    参考:
    https://docs.fluentd.org/parser/regexp
    https://github.com/fluent/fluentd/issues/1513

  • 相关阅读:
    spring filter and interceptor
    spring 与 swagger 2 的整合
    spring 异步操作
    图片延迟加载 jquery,lazyload.js 调用的demo
    一、Spring的第一个课时
    线程的基本了解
    HTTPS/HTTP监听常见问题
    Leetcode 118 杨辉三角
    HashSet的源码解释
    HashMap源码理解
  • 原文地址:https://www.cnblogs.com/lori/p/13731371.html
Copyright © 2011-2022 走看看