2.Beats 配置文件格式

2019-04-20  本文已影响0人  歌哥居士

概述

Beats配置文件采用YAML格式。

person:
  name: Baozi
  age: 22
colors:
  - Red
  - Green
  - Blue
person: {name: "Baozi", age: 22}
colors: ["Red", "Green", "Blue"]
filebeat:
  inputs:
    - type: log
      paths:
        - /var/log/*.log
      multiline:
        pattern: '^['
        match: after

filebeat.inputs:
- type: log
  paths: ["/var/log/*.log"]
  multiline.pattern: '^['
  multiline.match: after


filebeat.inputs:
- type: log
  paths:
    - /var/log/system.log
    - /var/log/wifi.log
- type: log
  paths:
    - "/var/log/apache2/*"
  fields:
    apache: true
  fields_under_root: true

命名空间

官网解释有点拗口,按我的理解简单解释下:读配置文件时,根据配置全路径,解析成命名空间,为折叠格式

output:
  elasticsearch:
    index: 'beat-%{[beat.version]}-%{+yyyy.MM.dd}'

会被解析成:output.elasticsearch.index: 'beat-%{[beat.version]}-%{+yyyy.MM.dd}',这就是所谓的命名空间折叠格式啦。

filebeat:
  inputs:
    - type: log

会被解析成: filebeat.inputs.0.type: log

filebeat.inputs:
- type: log
  paths: ["/var/log/*.log"]
  multiline.pattern: '^['
  multiline.match: after

output.elasticsearch.hosts: ["http://localhost:9200"]

数据类型

enabled: true
disabled: false
integer: 123
negative: -1
float: 5.4
duration1: 2.5s
duration2: 6h
duration_disabled: -1s

环境变量

环境变量 示例 结果
export NAME=elastic name: ${NAME} name: elastic
没有设置 name: ${NAME} name:
export NAME=elastic name: ${NAME:beats} name: elastic
没有设置 name: ${NAME:beats} name: beats
export NAME=elastic name: ${NAME:?你需要设置环境变量} 没有。返回自定义的错误信息。
没有设置 name: ${NAME:?你需要设置环境变量} name: elastic

定义复杂变量

export ES_HOSTS="10.45.3.2:9220,10.45.3.1:9230"

引用

output.elasticsearch:
  hosts: '${ES_HOSTS}'

引用变量

filebeat.registry: ${path.data}/registry
es.host: '${ES_HOST:localhost}'

output.elasticsearch:
  hosts: ['http://${es.host}:9200']

重复配置的情况

namespace1:
  subnamespace:
    host: localhost
    sleep: 1s

namespace2:
  subnamespace:
    host: localhost
    sleep: 1s


可以被重写为:

namespace1: ${shared}
namespace2: ${shared}

shared:
  subnamespace:
    host: localhost
    sleep: 1s

一些提示

上一篇下一篇

猜你喜欢

热点阅读