Filebeat 是一个轻量级的日志文件传输工具,用于将日志数据发送到 Elasticsearch 或 Logstash。要在 Ubuntu 上定制 Filebeat 的输出格式,你需要编辑 Filebeat 配置文件 filebeat.yml。
以下是一个示例,展示了如何在 Filebeat 配置文件中定制输出格式:
/etc/filebeat/filebeat.yml:sudo nano /etc/filebeat/filebeat.yml
在 filebeat.yml 文件中找到 output.elasticsearch 部分。这里你可以配置 Filebeat 将日志数据发送到 Elasticsearch 或 Logstash。
要定制输出格式,你需要在 output.elasticsearch 部分添加或修改 fields 和 fields_under_root 选项。例如,以下配置将添加一个名为 custom_field 的自定义字段,并将其值设置为 custom_value:
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{+yyyy.MM.dd}"
pipeline: "your_pipeline_name"
fields:
custom_field: "custom_value"
fields_under_root: true
output.logstash 部分进行类似的配置:output.logstash:
hosts: ["localhost:5000"]
codec => json_lines
fields:
custom_field: "custom_value"
fields_under_root: true
保存并关闭 filebeat.yml 文件。
重新启动 Filebeat 以应用更改:
sudo systemctl restart filebeat
现在,Filebeat 将按照你指定的输出格式发送日志数据。请注意,根据你的需求,你可能需要调整 Elasticsearch 索引模板以适应新的字段。