在Debian系统下,要自定义Filebeat的日志输出格式,你需要修改Filebeat的配置文件。以下是具体步骤:
/etc/filebeat/filebeat.yml
。使用文本编辑器打开它,例如使用nano编辑器:sudo nano /etc/filebeat/filebeat.yml
filebeat.yml
文件中,找到output.elasticsearch
部分。如果你还没有配置输出到Elasticsearch,请添加以下内容:output.elasticsearch:
hosts: ["localhost:9200"]
将localhost:9200
替换为你的Elasticsearch实例的地址和端口。
output.elasticsearch
部分下,添加fields_under_root
设置,将其设置为true
。这将使Filebeat将所有事件字段放在Elasticsearch文档的根级别,而不是嵌套在fields
字段中。output.elasticsearch:
hosts: ["localhost:9200"]
fields_under_root: true
filebeat.yml
文件中,找到fields
部分。在这里,你可以添加自定义字段,这些字段将附加到每个事件中。例如:fields:
custom_field1: "value1"
custom_field2: "value2"
保存并关闭filebeat.yml
文件。
重新启动Filebeat服务以应用更改:
sudo systemctl restart filebeat
现在,Filebeat将以自定义的格式输出日志。你可以在Elasticsearch中查看事件,看到自定义字段已添加到文档中。