Записать исключение Java на Docker Swarm + Fluentd - PullRequest
0 голосов
/ 17 ноября 2018

Я настроил конфигурацию в своем кластере роя, чтобы использовать fluentd для отправки журналов вasticsearch. Эта часть работает отлично, однако журналы исключений моих java-изображений появляются в каждой строке стека в записи. Я уже пробовал использовать плагин detect_exceptions и multiline, но мне кажется, что они работают только тогда, когда источник имеет тип «tail» (в моем случае это «forward»).

Мой стек.имл

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
.....

И мой беглый.конф

<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>

Не могли бы вы сказать, возможно ли это сделать (поместить весь стек исключений в запись), используя logging-драйвер fluentd на swarm?

Ответы [ 2 ]

0 голосов
/ 21 ноября 2018

Спасибо, оккез.Я смог решить эту проблему с помощью плагина 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>
0 голосов
/ 21 ноября 2018

Может быть, следующий фрагмент полезен (не проверен):

<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 .

...