【发布时间】:2021-01-05 16:24:41
【问题描述】:
使用:
- 流畅的 1.11.2
- fluent-plugin-elasticsearch 4.1.3
- 弹性搜索 7.5.1
- springboot 2.3.3
在 Openshift 中运行(Kubernetes v1.17.1+20ba474)。
Fluentd 和 Elasticsearch 都在不同的 pod 中运行。
Fluentd 配置文件:
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<filter *.**>
@type parser
key_name log
reserve_data true
<parse>
@type none
</parse>
</filter>
<match *.**>
@type copy
<store>
@type elasticsearch
host elasticdb
port 9200
logstash_format true
logstash_prefix applogs
logstash_dateformat %Y%m%d
include_tag_key true
type_name app_log
tag_key @log_name
flush_interval 1s
user elastic
password changeme
</store>
<store>
@type stdout
</store>
</match>
从本地 springboot 服务,我正在向 fluentd 发送一些虚拟数据:
// Local port 24224 is being forwarded to remote 24224 via oc port-forward command
private static FluentLogger LOG = FluentLogger.getLogger("app", "127.0.0.1", 24224);
Map<String, Object> data = new HashMap<String, Object>();
data.put("from", "userA");
data.put("to", "userB");
LOG.log("app", data);
发送这条 JSON 数据:
{"from":"userA","to":"userB"}
显然,它只工作十分之一。或者似乎工作了两三次然后中断,直到我更改索引。实际上,并不清楚行为模式。
当它不起作用时(大多数时候),这些是 fluentd pod 中的日志:
2020-09-18 17:33:08.000000000 +0000 app.appaa: {"from":"userA","to":"userB"}
2020-09-18 17:33:37 +0000 [warn]: #0 dump an error event: error_class=ArgumentError error="log does not exist" location=nil tag="fluent.warn" time=2020-09-18 17:33:37.328180192 +0000 record={"error"=>"#<ArgumentError: log does not exist>", "location"=>nil, "tag"=>"app.appaa", "time"=>1600450388, "record"=>{"from"=>"userA", "to"=>"userB"}, "message"=>"dump an error event: error_class=ArgumentError error=\"log does not exist\" location=nil tag=\"app.appaa\" time=1600450388 record={\"from\"=>\"userAa\", \"to\"=>\"userBb\"}"}
2020-09-18 17:33:37.328180192 +0000 fluent.warn: {"error":"#<ArgumentError: log does not exist>","location":null,"tag":"app.appaa","time":1600450388,"record":{"from":"userA","to":"userB"},"message":"dump an error event: error_class=ArgumentError error=\"log does not exist\" location=nil tag=\"app.appaa\" time=1600450388 record={\"from\"=>\"userA\", \"to\"=>\"userB\"}"}
warning: 299 Elasticsearch-7.5.1-3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96 "[types removal] Specifying types in bulk requests is deprecated."
尽管 Elasticsearch pod 没有显示任何内容(我猜是日志级别的问题),但如果我使用 Elastic,我会看到:
{
"_index": "applogs-20200918",
"_type": "_doc",
"_id": "F0M2onQBB89nIri4Cb1Z",
"_score": 1.0,
"_source": {
"error": "#<ArgumentError: log does not exist>",
"location": null,
"tag": "app.app",
"time": 1600449251,
"record": {
"from": "userA",
"to": "userB"
},
"message": "dump an error event: error_class=ArgumentError error=\"log does not exist\" location=nil tag=\"app.app\" time=1600449251 record={\"from\"=>\"userA\", \"to\"=>\"userB\"}",
"@timestamp": "2020-09-18T17:14:39.775332214+00:00",
"@log_name": "fluent.warn"
}
}
所以看起来错误来自
“弹性:参数错误:日志不存在”
以前有人遇到过这个错误吗?
【问题讨论】:
-
您是否使用
fluent-cat命令对此进行了测试? -
感谢您的评论。不,我没有。你认为这会有什么不同吗?在我正在做的所有尝试中,我正在从本地服务和在 OCP 上的单独 pod 中运行的同一服务攻击 fluentd。由于我在 Windows10 上,我对安装 fluent 代理不是很有信心。但是,如果您认为这会有所作为,我会尝试。再次感谢。
-
欢迎您!这将隔离 fluentd 和 elasticsearch 管道。您可以在运行 fluentd 的同一台机器上对其进行测试。
fluent-cat应该已经在那里了。您不必在不同的机器上单独安装它。这将有助于验证客户服务是否与此有关;而且,管道正在运行。 -
对。
key_name log。你可以试试echo '{"log":"hello"}' | fluent-cat debug.log吗? -
太棒了!是的,您应该参考文档进行配置。而且,我总是首先使用
fluent-cat来单独测试事物。很高兴它有帮助。 :)
标签: spring elasticsearch openshift fluentd