【问题标题】:Log java exception on docker swarm + fluentd在 docker swarm + fluentd 上记录 java 异常
【发布时间】:2018-11-17 13:33:34
【问题描述】:

我在我的 swarm 集群中进行了配置,以使用 fluentd 将日志发送到 elasticsearch。这部分工作正常,但是我的 java 图像的异常日志出现在记录中的每个堆栈行。 我已经尝试过使用 detect_exceptions 和多行插件,但在我看来,它们仅在源为“尾”类型(在我的情况下为“转发”)时才有效。

我的 stack.yml

version: '3.6'

....

services:

  myjavaservice:
    image: myjavaservice
    logging:
      driver: "fluentd"
      options:
        tag: myjavaservice
    deploy:
      placement:
        constraints: [node.role==worker]
      replicas: 1

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
    ports:
      - "9200:9200"
    logging:
      driver: "json-file"
      options:
        max-size: 10M
        max-file: 1
    volumes:
      - esdata:/usr/share/elasticsearch/data
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.hostname == manager

  fluentd:
    image: my.repo/fluentd
    volumes:
      - ./Logs:/fluentd/log
    ports:
      - "24224:24224"
      - "24224:24224/udp"
    deploy:
      replicas: 1
      placement:
        constraints: [node.role == manager]
      update_config:
        delay: 2s
.....

还有我的 fluentd.conf

<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

<filter *>
  @type record_transformer
  <record>
    hostname "#{Socket.gethostname}"
    tag ${tag}
  </record>
</filter>

<label @raw>
  <match myapp.*>
    @type detect_exceptions
    remove_tag_prefix myapp
    message log
    languages java
    multiline_flush_interval 0.5
  </match>

  <match *>
    @type copy
    <store>
      @type elasticsearch
      host elasticsearch
      port 9200
      logstash_format true
      logstash_prefix logstash
      logstash_dateformat %Y%m%d
      include_tag_key true
      tag_key @log_name
      flush_interval 1s
    </store>
  </match>
</label>

您能否告诉我是否可以使用 fluentd on swarm 上的日志记录驱动程序来执行此操作(将整个异常堆栈放入记录中)?

【问题讨论】:

    标签: java docker elasticsearch docker-swarm fluentd


    【解决方案1】:

    谢谢你。 我能够使用 concat 插件解决问题,但我也要测试你通过的这个解决方案。 这是我实施的解决方案:

    <source>
      @type forward
      port 24224
      bind 0.0.0.0
    </source>
    
    <filter **>
      @type concat
      key log
      stream_identity_key container_id
      multiline_start_regexp /^\S+/
      flush_interval 1s
      timeout_label @processdata
    </filter>
    
    <label @ERROR>
      <match **>
        @type stdout
      </match>
    </label>
    
    <label @processdata>
      <match **>
        @type stdout
      </match>
    </label>
    
    <match **>
      @type elasticsearch
      logstash_format true
      host elasticsearch
      port 9200
      index_name fluentd
      type_name fluentd
      flush_interval 5s
    </match>
    

    【讨论】:

      【解决方案2】:

      也许以下 sn-p 有帮助(未测试):

      <source>
        @type forward
        port 24224
        bind 0.0.0.0
        @label @INPUT
      </source>
      
      <label @INPUT>
        <filter>
          @type record_transformer
          <record>
            hostname "#{Socket.gethostname}"
            tag ${tag}
          </record>
        </filter>
      
        <match myapp.*>
          @type detect_exceptions
          remove_tag_prefix myapp
          message log
          languages java
          multiline_flush_interval 0.5
        </match>
        <match>
          @type relabel
          @label @OUTPUT
        </match>
      </label>
      
      <label @OUTPUT>
        <match>
          @type copy
          <store>
            @type elasticsearch
            host elasticsearch
            port 9200
            logstash_format true
            logstash_prefix logstash
            logstash_dateformat %Y%m%d
            include_tag_key true
            tag_key @log_name
            flush_interval 1s
          </store>
        </match>
      </label>
      

      这是使用@label定义内部路由的点。

      如果要将堆栈跟踪连接到一条记录中,可以使用fluent-plugin-concat

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-02
        • 2019-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多