以下是Filebeat在Debian上的高级功能使用方法,基于搜索结果整理:
处理器(Processor)
filebeat.inputs
中通过add_fields
处理器添加字段。processors:
- add_fields:
fields:
custom_field: "value"
decode_json_fields
处理器解析JSON格式日志。processors:
- decode_json_fields:
fields: ["message"]
target: "json"
add_host_metadata
或add_docker_metadata
处理器自动添加主机或容器信息。输入模块(Input)
multiline
配置合并多行日志(如Java异常堆栈)。filebeat.inputs:
- type: log
paths: ["/var/log/app/*.log"]
multiline:
pattern: '^\d{4}-\d{2}-\d{2}' # 匹配时间戳
negate: true
match: after
exclude_files
排除特定文件(如.gz
压缩文件)。输出模块(Output)
output.logstash
指定Logstash地址和负载均衡参数。output.logstash:
hosts: ["localhost:5044"]
worker: 2
loadbalance: true
output.kafka
配置Kafka主题和分区策略。output.kafka:
hosts: ["kafka:9092"]
topic: "%{[type]}"
partition: round_robin
性能优化
queue.type
设为persisted
,并调整queue.max_bytes
和flush.min_events
优化内存使用。harvester.limit
限制并行处理的文件数量。ignore_older
忽略旧文件,close_inactive
关闭非活动文件的harvester以释放资源。Filebeat提供预定义模块(如Nginx、MySQL),可快速启用并配置特定日志格式。
filebeat.modules:
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log*"]
error:
enabled: true
var.paths: ["/var/log/nginx/error.log*"]
启用模块后,需重启Filebeat使配置生效。
集成Kibana
filebeat-*
),使用Discover功能查看日志。日志过滤与告警
drop_event
处理器过滤特定日志(如DEBUG
级别日志)。filebeat test config
命令验证配置文件语法是否正确。journalctl -u filebeat -f
实时查看Filebeat运行状态和错误信息。