支持自定义字段的方式
在 Ubuntu 上的 Filebeat 支持通过多种方式为事件添加自定义字段,常见做法包括:
快速配置示例
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
fields:
env: prod
region: cn-beijing
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
fields:
env: prod
region: cn-beijing
fields_under_root: true
processors:
- add_fields:
fields:
team: "backend"
project: "order-service"
# 在系统环境或 /etc/profile 中导出变量
export SERVER_IP=192.168.1.10
# 在配置中引用
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
fields:
host_ip: ${SERVER_IP}
提示:远程执行 systemctl/脚本重启时,确保以 login shell 加载环境变量(如使用 bash -l),否则 Filebeat 可能读取不到变量导致启动失败。字段放置与作用域说明
在 Ubuntu 上的应用与验证步骤
sudo filebeat test config -c /etc/filebeat/filebeat.yml
sudo systemctl restart filebeat
sudo journalctl -u filebeat -f