我在集群集群中进行了配置,以使用fluentd将日志发送到elasticsearch。这部分工作正常,但是我的Java映像的异常日志出现在记录的每个堆栈行中。 我已经尝试过使用detect_exceptions和多行插件,但是在我看来,它们仅在源为“ tail”类型(在我的情况下为“ forward”)时才起作用。
我的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>
您能告诉我是否有可能使用流利的swarm日志记录驱动程序来执行此操作(将整个异常堆栈放入记录中)?
答案 0 :(得分:1)
谢谢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>
答案 1 :(得分:0)
以下代码段可能有用(未经测试):
<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。