在 Ubuntu 上 Filebeat 占用 CPU / 内存 / 磁盘 IO 过高,通常不是 Filebeat 本身有 bug,而是配置或采集环境不合理导致的。下面按「常见原因 → 排查方法 → 解决办法」给你梳理。
paths 配置过宽)表现
filebeat.metrics 中 harvester 数量很多解决
filebeat.inputs:
- type: log
paths:
- /var/log/nginx/access.log # 精确路径
scan_frequency: 10s # 降低扫描频率
harvester_limit: 50 # 限制 harvester 数量
paths:
- /var/log/*
- /var/lib/docker/containers/*
会扫描大量目录和已轮转文件。
解决
exclude_files: ['.gz$', '.zip$']
logrotate 频繁切割解决
close_inactive: 5m
clean_inactive: 72h
ignore_older: 24h
常见高消耗操作:
dissectjsonscript排查
filebeat modules list
解决
某些版本(如 7.x 早期)有 CPU 死循环问题。
检查
filebeat version
建议
/var/lib/filebeat/registry解决
systemctl stop filebeat
rm -rf /var/lib/filebeat/registry
systemctl start filebeat
⚠️ 会重新采集(慎用于生产)
Filebeat 会:
检查
filebeat test output
解决
worker# 查看资源占用
top -p $(pgrep filebeat)
# 查看采集状态
filebeat export config
# 查看 metrics
curl http://localhost:5066/stats
filebeat.inputs:
- type: log
paths:
- /var/log/nginx/*.log
exclude_files: ['.gz$']
scan_frequency: 10s
harvester_limit: 100
close_inactive: 5m
ignore_older: 24h
output.elasticsearch:
hosts: ["http://localhost:9200"]
worker: 4
你可以贴出:
filebeat.ymltop 截图我可以直接帮你精准定位是哪一条配置导致的。