环境
window10
版本:filebeat-7.16.3
下载:
filebeathttps://www.elastic.co/cn/downloads/past-releases#filebeat
目录
Filebeat用于转发、采集日志数据的轻量级程序,filebeat监视指定目录位置或指定文件,采集日志,可将其转发输出到Elasticsearch、Logstash、Kafka、Redis、File、Console、Cloud等
LogStash较重量级,占用资源更高,Filebeat占用资源少,部署简单,常用于采集日志,输出到LogStash
轻量型数据采集器 beats 完整系列:
filebeat目录结构:
配置filebeat.yml
filebeat模块module
## 查看module集合
filebeat modules list
## 启用module
filebeat modules enable module名称
## 禁用module
filebeat modules disable module名称
简单配置input输入源
filebeat.inputs:
- type: log
enabled: true
paths:
- C:\LogSampleData\*.log
- c:\programdata\elasticsearch\logs\*.logtags: ["标签一","标签二"]
fields:
source: invoice
# 表示fields字段加在根节点下
fields_under_root: truefilebeat.inputs:
- type: log
enabled: true
paths:
- C:\filebeat-7.16.3-windows-x86_64\LogSampleData\*.log
- c:\programdata\logs\*.log- c:\programdata\*\*.log # 匹配 c:\programdata 目录下面所有文件夹下的所有log文件
配置了两个filebeat.inputs节点,用于配置多个来源
1: 配置采集C:\LogSampleData目录下所有.log后缀文件、c:\programdata\elasticsearch\logs目录下所有文件
2:配置采集C:\filebeat-7.16.3-windows-x86_64\LogSampleData目录下所有.log后缀文件、c:\programdata\logs\目录下所有文件
节点:
enabled:使用该enabled
选项启用和禁用输入。默认情况下,启用设置为真
tags:Filebeat 在tags
每个已发布事件的字段中包含的标签列表。标签使在 Kibana 中选择特定事件或在 Logstash 中应用条件过滤变得容易。这些标签将附加到常规配置中指定的标签列表中。
paths:指定采集日志路径
fields:附加字段
fields_under_root:表示fields字段加在根节点下,否则会作为fields的子节点存在
输出output配置
Elasticsearch 输出Output
output.elasticsearch: hosts: ["localhost:9200"]
Logstash 输出Output
output.logstash:
hosts: ["127.0.0.1:5044"]
filebeat在Kibana展示
setup.kibana:
host: "localhost:5601"
filebeat高级配置
filebeat.yml:
filebeat.inputs:
- type: log
enabled: true
paths:
- C:\Code\Servicelog\OpenApi\2022-01\2022-01-10\*.log
tags: ["标签一"]
filebeat 默认匹配单行消息
示例:
Information 2022/1/24 13:28:41 【|CloudService.ElectronicInvoice|ElectronictInvoiceQH.InvoiceHisIssue|电子票据开具开始:
{
"bizType": "06",
"payNo": "176755",
"visitNo": "100033293",
"source": "定时任务",
"updateUserNo": -5,
"seeType": 0
}】
查看kibana
可以看到filebeat 默认会将每一行作为一条文本消息,不利于查看日志消息
修改:filebeat.yml:
添加 multiline.type 、multiline.pattern、multiline.negate、multiline.match 节点
filebeat.inputs:
- type: log
enabled: true
paths:
- C:\Code\ervicelog\OpenApi\2022-01\2022-01-10\*.log
tags: ["标签一"]
multiline.type: pattern
multiline.pattern: '^Information' # 正则表达式
multiline.negate: true # true 或 false;默认是false,匹配pattern的行合并到上一行;true,不匹配pattern的行合并到上一行
multiline.match: after # after 或 before,合并到上一行的末尾或开头multiline.flush_pattern: '】$' # 匹配结束消息,匹配】结尾的消息
修改后效果,查看kibana
2、索引:
默认索引格式:
filebeat-%{[beat.version]}-%{+yyyy.MM.dd}
如:filebeat-2022.01.26-000001
自定义索引格式,修改filebeat.yml:
# ============================== Filebeat inputs ===============================
filebeat.inputs:
- type: log
enabled: true
paths:
- C:\Code\NewHis\trunk_New\Code\05-ThirdPart\Servicelog\OpenApi\2022-01\2022-01-10\*.log
tags: ["发票"]
fields:
source: invoice
multiline.type: pattern
multiline.pattern: '^Information'
multiline.negate: true
multiline.match: after
multiline.flush_pattern: '】$'
# ---------------------------- Elasticsearch Output ----------------------------
# # 如果存在模块则覆盖
setup.template.overwrite: true
# # 生成index模板的名称
setup.template.name: "filebeat-7.16.3"
# # 生成index模板匹配的index格式
setup.template.pattern: "filebeat-7.16.3-*"
# 索引生命周期
#对Filebeat创建的任何新索引启用或禁用索引生命周期管理。有效值是true,false和auto。如果auto在7.0版和更高版本上指定了(默认值),则Filebeat会自动使用索引生命周期管理;否则,Filebeat会每日创建索引
setup.ilm.enabled: false
setup.ilm.rollover_alias: "filebeat" # 索引生命周期写别名
setup.ilm.pattern: "{now/d}" # 滚动索引模式。默认值为%{now/d}-000001
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"]
index: "filebeat-%{[fields.source]}-*"
indices:
- index: "filebeat-invoice-%{+yyyy.MM.dd}"
when.equals:
fields:
source: "invoice"
- index: "filebeat-chargeout-%{+yyyy.MM.dd}"
when.equals:
fields:
source: "chargeout"
根据fields自定义字段值,自动匹配创建相对应的索引
运行filebeat
cmd运行filebeat
启用配置elasticsearch 模块
filebeat.exe modules enable elasticsearch
默认启动
filebeat -e
指定 filebeat.yml 配置文件启动
filebeat -e -c filebeat.yml