在CentOS中,Filebeat可以通过配置文件中的processors来进行日志过滤。以下是一些常用的日志过滤方法:
在Filebeat的配置文件(filebeat.yml)中,可以使用ignore_files和ignore_dirs选项来忽略特定的文件或目录。例如:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
ignore_files: ['*.log.1', 'temp.log']
ignore_dirs: ['cache', 'logs']
这将忽略所有以.log.1结尾的文件和名为temp.log的文件,同时忽略cache和logs目录。
如果需要包含特定的文件或目录,可以使用include_files和include_dirs选项。例如:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
include_files: ['access.log']
include_dirs: ['logs']
这将只包含名为access.log的文件和logs目录。
Filebeat支持使用processors对日志进行更复杂的过滤。例如,可以使用dissect处理器解析日志,并根据解析结果进行过滤。以下是一个示例配置:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/myapp/*.log
processors:
- dissect:
tokenizer: '%{timestamp} %{level} %{message}'
field: 'message'
target_prefix: ''
when:
contains:
message: 'ERROR'
output.elasticsearch:
hosts: ["localhost:9200"]
这个配置将解析名为myapp的目录下的所有日志文件,并从中提取时间戳、日志级别和消息。然后,它将只输出包含"ERROR"的消息。
注意:在使用processors时,需要确保已安装并启用了相应的数据处理器。在上面的示例中,需要安装filebeat-module-discover-nginx模块以启用dissect处理器。
更多关于Filebeat日志过滤的信息,请参考官方文档:https://www.elastic.co/guide/en/beats/filebeat/current/filtering-events.html