Filebeat-应用


1. filebeat 语法

[root@progs filebeat]# ./filebeat -h
Usage:
filebeat [flags]
filebeat [command]

Available Commands:
enroll     Enroll in Kibana for Central Management
  export     Export current config or index template
help       Help about any command
keystore   Manage secrets keystore
modules     Manage configured modules
run         Run filebeat
setup       Setup index template, dashboards and ML jobs
test       Test config
version     Show current version info

Flags:
  -E, --E setting=value     Configuration overwrite
  -M, --M setting=value     Module configuration overwrite
  -N, --N                   Disable actual publishing for testing
  -c, --c string             Configuration file, relative to path.config (default "filebeat.yml")
      --cpuprofile string   Write cpu profile to file
  -d, --d string             Enable certain debug selectors
  -e, --e                   Log to stderr and disable syslog/file output
  -h, --help                 help for filebeat
      --httpprof string     Start pprof http server
      --memprofile string   Write memory profile to this file
      --modules string       List of enabled modules (comma separated)
      --once                 Run filebeat only once until all harvesters reach EOF
      --path.config string   Configuration path
      --path.data string     Data path
      --path.home string     Home path
      --path.logs string     Logs path
      --plugin pluginList   Load additional plugins
      --setup               Load sample Kibana dashboards and setup Machine Learning
      --strict.perms         Strict permission checking on config files (default true)
  -v, --v                   Log at INFO lev

2. filebeat配置

2.1 输入配置

文档

2.1.1 通用选项

filebeat.registry_file: registry | 默认值 ${path.data}/registry filebeat.registry_file_permissions: 0600 | 注册文件权限 filebeat.registry_flush | 控制将注册项写入磁盘的超时时间,默认为0秒 filebeat.shutdown_timeout | Filebeat在关闭之前等待发布者完成发送事件的关闭时间。默认为禁用

enabled | 启用和禁用输入。默认值为true tags | 添加标签 fields | 指定额外信息到输出中 fields_under_root | true: 将自定义的字段作为顶级字段存储在输出 processors | 应用于输入数据的处理器列表 pipeline | 要为此输入生成的事件设置的接收节点管道ID name | 设置名称,如果为空,则用服务器的主机名 max_procs | 并发执行最大CPU数量。默认值为系统中可用的逻辑CPU的数量

2.1.2 Log 日志类型
1)Filebeat 如何区分不同日志来源
# 配置多个input节点的方式采集多个不同业务日志文件,如下:

filebeat.inputs:
- type: log   # <<< (1)
paths:
    - /var/log/system.log
    - /var/log/wifi.log
   
- type: log  # <<< (2)
paths:
    - "/var/log/apache2/*"
fields:
   apache: true
fields_under_root: true
 
# (1) 从两个文件[system.log,wifi.log]中获取行
# (2) 从apache2目录中的每个文件中采集行,并使用fields配置选项将名为apache的字段添加到输出中。

==注意:== 1)一个文件不要多次定义输入; 2)不要使用软连接配置文件路径

2)配置选项

paths | 指定本地中可以获取的绝对路径文件列表,可以使用go glob支持的模式。 recursive_glob.enabled: true | 设置以递归方式获取目录所有子目录中的所有匹配的文件,默认为false即,禁用。 encoding | 读取数据的文件编码 exclude_lines | 排除正则表达式列表匹配的行,默认忽略空行。如:exclude_lines: ['^DBG'] include_lines | 匹配正则表达式列表匹配的行,默认忽略空行。 如:include_lines: ['^ERR', '^WARN'] ==注意:== 如果同时配置exclude_lines和include_lines,首先执行include_lines,再执行exclude_lines.与顺序无关。

harvester_buffer_size | 配置harvester获取文件时使用缓冲区大小(以字节为单位)。默认值为16384 max_bytes | 每条日志消息的最大字节数,默认10MB(10485760)

json | filebeat可以解码结构化为json格式的日志 ==注意:指定以下设置之一才可以启用json解析模式== json.keys_under_root: true | json对象的key会传递给输出,默认为false json.overwrite_keys: true | json对象key发生冲突时,json对象将覆盖filebeat默认添加的字段 json.add_error_key: true | 当json解析出错时或是在配置中定义message_key不可用时,filebeat自动添加"error.message"和"error.type:json"两个键。 json.message_key: true | 设置json密钥,可选项 json.ignore_decoding_error: true | 是否记录json解析错误信息,可选项,默认值为false。

multiline | 控制filebeat如何处理多行消息日志。 multiline.pattern | 正则表达式 multiline.negate | 默认值为false, 按照模式进行匹配。假如模式为'^b',false:将以b开头的连续行合并;true:将不以b开头的连续行合并 multiline.match | [after|before],指定将模式匹配的多行组合方式,after: negate指定行在后(后出现);before: negate指定行在前(先出现) multiline.flush_pattern | 将从内存中刷新当前多行,从而结束多行消息。 multiline.max_lines | 定义最大的行数,默认值500 multiline.timeout | 定义超时时间,默认值为5秒

multiline

exclude_files | 忽略正则表达式列表中匹配的文件 ignore_older | 忽略指定时间之前修改过的文件,igonre_older必须大于close_inactive close_inactive: true | 在指定时间内未收集到新行,则关闭文件句柄。 close_renamed | 如果文件被重命名和移动,则关闭文件句柄 close_removed: true | 在删除文件时关闭harvester。 close_eof | 适合只写一次日志的文件,然后filebeat关闭文件句柄 close_timeout | 每个harvester设置预定义时间后关闭

clean_inactive: true | 经过指定的非活动时间后,filebeat会删除问及爱你的状态。clean_inactive必须大于ignore_older + scan_frequency clean_removed | 当磁盘上找不到标识的文件时,filebeat将从注册文件中清除,默认启动该选项 scan_frequency | 指定扫描文件的时间频率,默认值为10秒 scan.ssort | scan.order | 指定使用排序规则,升序还是降序 tail_files | true: 将在每个文件的尾部开始读取新行消息;默认值为false symlinks | 允许收集符号连接文件(如:Kubernetes日志) backoff | 定义到达EOF后Filebeat在再次检查文件之前等待的时间。默认值为1s max_backoff | 达到EOF后,Filebeat等待再次检查文件的最长时间, 默认值为10秒。backoff <= max_backoff <= scan_frequency backoff_factor | 指定等待时间的系数 harvester_limit | 限制havaester的数量,默认值为0,即没有限制。

2.2 内部队列

在发布事件之前Filebeat使用内部队列存储事件消息。

2.2.1 配置内存队列

queue.mem: events: 4096 flush.min_events: 512 flush.timeout: 5s

2.3 输出配置
2.4 filebeat支持的正则表达式

== 注意:使用单引号括起来 ==

文档

模式
描述

Single Characters

x
匹配指定的一个字符

.
匹配任意一个字符

[xyz]
匹配x,y,z任一字符

[^xyz]
匹配除x,y,z外任一字符

[[:alpha:]]
匹配ASCII表中任一字符

[[:^alpha:]]
匹配ASCII表外任一字符

\d

\D

\pN

\p{Greek}

\PN

\P{Greek}

Composites

xy

x|y

Repetitions

x*

x+

x?

x{n,m}

x{n,}

x{n}

x*?

x+?

x??

x{n,m}?

x{n,}?

x{n}?

Grouping

(re)

(?P<name>re)

(?:re)

(?i)abc

(?i:re)

(?i)PaTTeRN

(?m)multiline

(?s)pattern.

(?U)x*abc

Empty Strings

^

$

\A

\b

\B

\z

Escape Sequences

\a

\f

\t

\n

\r

\v

*

\123

\x7F

\x{10FFFF}

\Q...\E

ASCII Character Classes

[[:alnum:]]

[[:alpha:]]

[[:ascii:]]

[[:blank:]]

[[:cntrl:]]

[[:digit:]]

[[:graph:]]

[[:lower:]]

[[:print:]]

[[:punct:]]

[[:space:]]

[[:upper:]]

[[:word:]]

[[:xdigit:]]

Supported Perl Character Classes

\d

\D

\s

\S

\w

\W

2.5 测试配置文件
./filebeat test config -c config/filebeat2kafka.yml

3. 常见问题

3.1 注册文件太大

合理允许clean_inactive和clean_removed解决

3.2 inode重用导致跳行

合理允许clean_inactive和clean_removed解决

3.3 使用过多CPU

检查设置scan_frequency配置值

猜你喜欢

转载自www.cnblogs.com/binliubiao/p/12726589.html
今日推荐