java - 在 docker swarm + fluentd 上记录 java 异常
问题描述
我在我的 swarm 集群中进行了配置,以使用 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 上使用日志驱动程序流利地执行此操作(将整个异常堆栈放在记录中)?
解决方案
谢谢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>
推荐阅读
- java - 使用杰克逊的弹簧过滤响应字段
- html - 在vue js中延迟从随机图像url加载不同的图像失败
- javascript - Redux 状态 - 只有有时它显示“状态相等”
- c# - 在 Unity 中完成后退出聊天窗口
- locking - 为什么带有 SPI_SETMOUSESPEED 的 SystemParametersInfo 会挂起?有什么解决办法
- r - 在雪花表中追加数据
- python - 让 tkinter GUI 在意外关闭时打开以前关闭的数据
- python - 如何获取在 Python 中打开的文件中的行号
- cmd - 如何将 Unicode 参数传递给 G++?
- java - 如何解决java中增强for循环中的这个错误?