在 CentOS 上,Filebeat 过滤数据主要通过 processors(处理器) 和 input 配置 来实现,而不是像 Logstash 那样用 filter 插件。下面按常见场景给你说明。
Filebeat 过滤主要依靠:
配置文件一般在:
/etc/filebeat/filebeat.yml
修改后重启:
systemctl restart filebeat
filebeat.inputs:
- type: log
paths:
- /var/log/app/*.log
include_lines: ['ERROR', 'WARN']
✅ 只采集包含 ERROR 或 WARN 的行
filebeat.inputs:
- type: log
paths:
- /var/log/app/*.log
exclude_lines: ['DEBUG', 'INFO']
✅ 忽略 DEBUG / INFO 日志
示例:丢弃 status=200 的日志
processors:
- drop_event:
when:
contains:
message: "status=200"
processors:
- drop_event:
when:
equals:
log.level: "info"
processors:
- drop_fields:
fields: ["agent.version", "ecs.version"]
processors:
- add_fields:
target: ''
fields:
env: production
processors:
- drop_event:
when:
regexp:
message: "^DEBUG"
processors:
- drop_event:
when:
and:
- contains:
message: "test"
- equals:
log.level: "debug"
filebeat.inputs:
- type: log
paths:
- /var/log/app.log
include_lines: ['ERROR']
output.elasticsearch:
hosts: ["http://localhost:9200"]
processors:
- drop_event:
when:
contains:
message: "health check"
filebeat.inputs:
- type: log
paths:
- /var/log/app.log
fields:
type: app
processors:
- drop_event:
when:
not:
equals:
fields.type: app
❗ Filebeat 不能做复杂解析(如 JSON 拆分、grok)
❗ 复杂处理建议:
Filebeat → Kafka / Logstash → ES
或:
Filebeat → ES(简单过滤)
filebeat test config
filebeat test output
查看实际发送内容:
filebeat -e -c /etc/filebeat/filebeat.yml
如果你愿意,可以告诉我:
我可以帮你写一份可直接用的 filebeat.yml。