簡要來說:
使用filebeat讀取log日志,在filebeat.yml中先一步處理日志中的個別數據,比如丟棄某些數據項,增加某些數據項。
按照之前的文檔,是在filebeat.yml中操作的,具體設置如下:
filebeat.inputs:
- type: log
enabled: true
fields:
apache: true
tags: ["my-service", "hardware", "test"]
paths:
- /Users/liuxg/data/apache-daily-access.log
processors: # 注意這幾行,表示的是刪除日志中的ecs這一項
- drop_fields:
fields: ["ecs"]
output.elasticsearch:
hosts: ["localhost:9200"]
現在不采用直接在filebet.yml文件中修改的方法,直接使用創建單獨的pipeline,在output.elasticsearch中引用這個pipeline從而達到上述效果:
定義一個Pipleline:
PUT _ingest/pipeline/my_pipeline_id
{
"description": "Drop ECS field and add one new field",
"processors": [
{
"remove": { # 移除日志中的ecs
"field": "ecs"
},
"set": { # 新增加一個,默認值是0
"field": "added_field",
"value": 0
}
}
]
}
這里my-pipleline-id是我們自己命令的在該cluster唯一標識是的pipleline ID
引用這個
filebeat.inputs:
- type: log
enabled: true
fields:
apache: true
paths:
- /Users/liuxg/data/apache-daily-access.log
output.elasticsearch:
hosts: ["localhost:9200"]
pipeline: "my_pipeline_id" # 注意這一行
感覺采用后者的方式比采用前者的方式功能更強大,可配置靈活性更好