gpt4 book ai didi

elasticsearch - 如何在 Filebeat/ELK 中为不同的日志定义单独的索引?

转载 作者:行者123 更新时间:2023-11-29 02:48:03 24 4
gpt4 key购买 nike

我想知道如何为提取到 logstash(后来传递到 elasticsearch)的不同日志创建单独的索引,以便在 kibana,我可以为它们定义两个索引并发现它们。

在我的例子中,我有几个客户端服务器(每个都安装了 filebeat)和一个集中式日志服务器(ELK)。每个客户端服务器都有不同种类的日志,例如redis.log, python 日志, mongodb 日志, 我喜欢把它们整理成不同的索引存储在elasticsearch.

每个客户端服务器也有不同的用途,例如数据库、用户界面、应用程序。因此我也喜欢给它们不同的索引名称(通过更改 filebeat.yml 中的输出索引?)。

最佳答案

在您的 Filebeat 配置中,您可以使用 document_type识别您拥有的不同日志。然后在 Logstash 内部,您可以设置 type 字段的值来控制目标索引。

然而,在将日志分成不同的索引之前,您应该考虑将它们留在一个索引中并使用 type 或一些 custom field区分日志类型。参见 index vs type .

示例 Filebeat 探矿者配置:

filebeat:
prospectors:
- paths:
- /var/log/redis/*.log
document_type: redis

- paths:
- /var/log/python/*.log
document_type: python

- paths:
- /var/log/mongodb/*.log
document_type: mongodb

示例 Logstash 配置:

input {
beats {
port => 5044
}
}

output {
# Customize elasticsearch output for Filebeat.
if [@metadata][beat] == "filebeat" {
elasticsearch {
hosts => "localhost:9200"
manage_template => false
# Use the Filebeat document_type value for the Elasticsearch index name.
index => "%{[@metadata][type]}-%{+YYYY.MM.dd}"
document_type => "log"
}
}
}

关于elasticsearch - 如何在 Filebeat/ELK 中为不同的日志定义单独的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38830663/

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