gpt4 book ai didi

node.js - NodeJS Bunyan Logstash 日志索引

转载 作者:搜寻专家 更新时间:2023-11-01 00:00:55 24 4
gpt4 key购买 nike

我正在使用 Bunyan 和 bunyas-lumberjack 将我的日志发送到日志存储并在 Elasticsearch 中为它们编制索引。我面临的问题是当我过滤日志时:我正在使用 Logstash 的基本过滤器:

filter {
if [type == "json"]{
json {
source => "message"
}
}
}

将来自 bunyan 的 JSON 放入 source.message 字段并在 Elasticsearch 中对其进行索引。我如何将 bunyan 中的每个字段索引到特定的 Elasticsearch 字段中,以便我可以搜索它或在 Kibana 中使用它?

我附上我现在获得的和我想获得的作为例子。目前:

{
"_index": "logstash-2015.10.26",
"_type": "json",
"_id": "AVCjvDHWHiX5VLMgQZIC",
"_score": null,
"_source": {
"message": "{\"name\":\"myLog\",\"hostname\":\"atnm-4.local\",\"pid\":6210,\"level\":\"error\",\"message\":\"This should work!\",\"@timestamp\":\"2015-10-26T10:40:29.503Z\",\"tags\":[\"bunyan\"],\"source\":\"atnm-4.local/node\"}",
"@version": "1",
"@timestamp": "2015-10-26T10:40:31.184Z",
"type": "json",
"host": "atnm-4.local",
"bunyanLevel": "50"
},

通缉:

{
"_index": "logstash-2015.10.26",
"_type": "json",
"_id": "AVCjvDHWHiX5VLMgQZIC",
"_score": null,
"_source": {
"message": {
"name": example,
"hostname": example,
"etc": example

最佳答案

logstash 中的每个输入都可以有不同的编解码器和类型。在你的例子中,如果你想索引 bunyan 和 syslog,你将有两个具有两种不同类型的输入。 syslog 的编解码器是“plain”,bunyan 的编解码器是“json”。 bunyan 消息不需要任何过滤器。 json 将被解析并且字段将自动出现。您将必须有一个过滤器来解析系统日志输入。

关于node.js - NodeJS Bunyan Logstash 日志索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33343884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com