Filebeat 是一个轻量级的日志文件传输工具,用于将日志数据发送到 Elasticsearch 或 Logstash。要在 Ubuntu 上定制 Filebeat 的输出格式,你需要编辑 Filebeat 配置文件 filebeat.yml。
以下是一个示例,展示了如何在 Filebeat 配置文件中定制输出格式:
- 打开终端,使用文本编辑器(如 nano 或 vim)打开 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
- 如果你想将自定义字段添加到 Logstash,可以在
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 索引模板以适应新的字段。
以上就是关于“filebeat在ubuntu上如何定制输出格式”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm