Filebeat

filebeat采集到ES 去掉host字段
在使用Filebeat将日志数据发送到Elasticsearch (ES) 之前,有时我们可能希望去掉或修改某些字段,比如host字段。这是因为某些日志数据可能包含敏感信息或者我们只需要特定的字段。在Filebeat中,可以通过配置文件来实现字段的去除或修改。

方法1:使用Filebeat的processors配置
Filebeat支持在配置文件中使用processors来处理和修改日志数据。你可以在Filebeat的配置文件中添加一个remove处理器来删除host字段。

例如,你的Filebeat配置文件(通常是filebeat.yml)可以这样配置:

filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log

processors:
- drop_fields:
fields: ["host"]

output.elasticsearch:
hosts: ["localhost:9200"]
indices:
- index: "logs-%{[agent.version]}-%{+yyyy.MM.dd}"


指定字符编码
在Filebeat的输入部分,指定正确的字符编码。例如,如果你的日志文件是UTF-8编码,你应该在filebeat.yml中这样配置:

filebeat.inputs:
- type: log
enabled: true
paths:
- /path/to/your/logfiles/*.log
encoding: utf-8


filebeat采集多个日志文件,每个日志文件的开始符不同
1. 配置文件结构
首先,确保你的Filebeat配置文件(通常是filebeat.yml)的结构如下:

filebeat.inputs:

- type: log
enabled: true
paths:
- /path/to/your/logfile1.log
fields_under_root: true
fields:
log_type: logfile1

- type: log
enabled: true
paths:
- /path/to/your/logfile2.log
fields_under_root: true
fields:
log_type: logfile2

# 可以继续添加更多输入配置以采集其他日志文件

output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[@metadata][beat]}-%{+yyyy.MM.dd}"


filebeat采集多个日志文件,每个日志文件配置不同的elasticsearch index
filebeat.config:
inputs:
# Disable config based autoloading of configs. Default is true
enabled: false

filebeat.inputs:
- type: log
enabled: true
paths:
- /path/to/your/logfile1.log
fields:
log_source: logfile1
# 设定Elasticsearch索引名称
index: "my-index-logfile1"

- type: log
enabled: true
paths:
- /path/to/your/logfile2.log
fields:
log_source: logfile2
# 设定另一个Elasticsearch索引名称
index: "my-index-logfile2"

output.elasticsearch:
hosts: ["http://localhost:9200"]
# 如果Elasticsearch设置了用户名和密码,可以这样配置
# username: "user"
# password: "pass"

posted @ 2025-09-03 16:27  selening_chan  阅读(21)  评论(0)    收藏  举报