Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在docker swarm上记录java异常+;弗伦特_Java_Docker_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Docker Swarm_Fluentd - Fatal编程技术网 elasticsearch,docker-swarm,fluentd,Java,Docker,elasticsearch,Docker Swarm,Fluentd" /> elasticsearch,docker-swarm,fluentd,Java,Docker,elasticsearch,Docker Swarm,Fluentd" />

在docker swarm上记录java异常+;弗伦特

在docker swarm上记录java异常+;弗伦特,java,docker,elasticsearch,docker-swarm,fluentd,Java,Docker,elasticsearch,Docker Swarm,Fluentd,我在swarm集群中做了一个配置,使用fluentd将日志发送到elasticsearch。这部分工作得很好,但是我的java映像的异常日志会出现在记录的每一个堆栈行中。 我已经尝试过使用detect_异常和多行插件,但在我看来,它们只在源代码为“tail”类型(在我的例子中是“forward”)时才起作用 我的堆栈.yml version: '3.6' .... services: myjavaservice: image: myjavaservice logging

我在swarm集群中做了一个配置,使用fluentd将日志发送到elasticsearch。这部分工作得很好,但是我的java映像的异常日志会出现在记录的每一个堆栈行中。 我已经尝试过使用detect_异常和多行插件,但在我看来,它们只在源代码为“tail”类型(在我的例子中是“forward”)时才起作用

我的堆栈.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>

@打字前进
端口24224
绑定0.0.0.0
@型记录变压器
主机名“#{Socket.gethostname}”
标记${tag}
@类型检测\u异常
删除标签前缀myapp
消息日志
java语言
多行\u刷新\u间隔0.5
@打印副本
@类型弹性搜索
主机弹性搜索
端口9200
logstash_格式为true
logstash_前缀logstash
日志存储\u日期格式%Y%m%d
包含标记键为真
tag_key@log_name
冲洗间隔1s

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

以下代码片段可能会有所帮助(未经测试):


@打字前进
端口24224
绑定0.0.0.0
@标签@输入
@型记录变压器
主机名“#{Socket.gethostname}”
标记${tag}
@类型检测\u异常
删除标签前缀myapp
消息日志
java语言
多行\u刷新\u间隔0.5
@类型重新标记
@标签@输出
@打印副本
@类型弹性搜索
主机弹性搜索
端口9200
logstash_格式为true
logstash_前缀logstash
日志存储\u日期格式%Y%m%d
包含标记键为真
tag_key@log_name
冲洗间隔1s
它是使用
@label
定义内部布线的点

如果要将堆栈跟踪连接到一个记录中,可以使用。

谢谢okkez。 我可以用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>

@打字前进
端口24224
绑定0.0.0.0
@海螺型
密钥日志
流\u标识\u密钥容器\u id
多行\u开始\u regexp/^\S+/
冲洗间隔1s
超时\u标签@processdata
@类型标准输出
@类型标准输出
@类型弹性搜索
logstash_格式为true
主机弹性搜索
端口9200
索引名称fluentd
键入\u name fluentd
冲洗间隔5s
<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>