在 Debian 上,Filebeat 主要用于采集日志并发送到后端(Elasticsearch / Logstash / Kafka 等),本身不是强大的数据处理工具,但可以通过 processors(处理器) 来过滤、丢弃、修改数据。
下面按常见需求给你讲几种在 Debian 上 Filebeat 过滤数据的方法。
Filebeat 的过滤主要在 filebeat.yml 里通过 processors 配置。
示例位置:
filebeat.inputs:
- type: log
paths:
- /var/log/app/*.log
processors:
- drop_event.when:
contains:
message: "health check"
processors:
- drop_event.when:
contains:
message: "DEBUG"
或正则:
processors:
- drop_event.when:
regexp:
message: "^GET /health"
processors:
- drop_event.when.not:
contains:
message: "ERROR"
意思是:不是 ERROR 的都丢掉。
如果日志是 JSON:
{"level":"info","msg":"test"}
processors:
- drop_event.when:
equals:
level: "debug"
processors:
- drop_event.when:
equals:
log.file.path: "/var/log/app/debug.log"
删除字段:
processors:
- drop_fields:
fields: ["agent.version", "ecs.version"]
添加字段:
processors:
- add_fields:
target: ''
fields:
env: production
processors:
- drop_event.when:
and:
- contains:
message: "test"
- equals:
level: "debug"
sudo filebeat test config
sudo filebeat test output
开启调试:
sudo filebeat -e -d "*"
或临时输出到 console:
output.console:
pretty: true
✅ Filebeat 不能做复杂聚合
❌ 不适合做 SQL 级别分析
✅ 复杂过滤推荐:
典型架构:
Filebeat → Logstash → Elasticsearch
filebeat.inputs:
- type: log
paths:
- /var/log/app/*.log
processors:
- drop_event.when:
contains:
message: "health"
output.elasticsearch:
hosts: ["http://localhost:9200"]
如果你愿意,可以告诉我:
我可以直接帮你写一份 可用的 filebeat.yml。