Beats 平台
也就是说,所有的 beat 工具,在配置上,除了 input 以外,在 output、filter、shipper、logging、run-options 上的配置规则都是完全一致的。
5.0 版本后,beats 新增了简单的 filter 功能,用来完成事件过滤和字段删减:
- equals
- contains
- regexp
- range
- or
- and
- not
目前 beat 可以发送数据给 Elasticsearch、Logstash、File、Kafka、Redis 和 Console 六种目的地址。
beats 发送到 Elasticsearch 也是走 HTTP 接口。示例配置段如下:
elasticsearch:
hosts: ["http://localhost:9200", "https://onesslip:9200/path", "anotherip"]
parameters: {pipeline: my_pipeline_id} # 仅用于 Elasticsearch 5.0 以后的 ingest 方式
username: "user"
password: "pwd"
index: "topbeat"
bulk_max_size: 20000
flush_interval: 5
tls:
certificate_authorities: ["/etc/pki/root/ca.pem"]
certificate: "/etc/pki/client/cert.pem"
certificatekey: "/etc/pki/client/cert.key"
index
表示写入 Elasticsearch 时索引的前缀,比如示例即表示索引名为topbeat-yyyy.MM.dd
Logstash
input {
beats {
port => 5044
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
}
}
beat 示例配置段如下:
这里 worker
的含义,是 beat 连到每个 host 的线程数。在 loadbalance
开启的情况下,意味着有 4 个worker 轮训发送数据。
output:
file:
path: "/tmp/topbeat"
filename: topbeat
rotate_every_kb: 1000
number_of_files: 7
Kafka
output:
kafka:
hosts: ["kafka1:9092", "kafka2:9092", "kafka3:9092"]
topic: '%{[type]}'
topics:
- key: "info_list"
when:
contains:
message: "INFO"
- key: "debug_list"
when:
contains:
- key: "%{[type]}"
"http": "frontend_list"
"nginx": "frontend_list"
"mysql": "backend_list"
partition:
round_robin:
reachable_only: true
required_acks: 1
compression: gzip
max_message_bytes: 1000000
- 大于
max_message_bytes
长度的事件(注意不只是原日志长度)会被直接丢弃。 - partition 策略默认为 hash。可选项还有 random 和 round_robin。
- compression 可选项还有 none 和 snappy。
- required_acks 可选项有 -1、0 和 1。分别代表:等待全部副本完成、不等待、等待本地完成。
- topics 用来配置基于匹配规则的选择器,支持 when 和 mapping,when 条件下可以使用上小节列出的各种 filter。如果都匹配不上,则采用 topic 配置。
Console
output:
console:
pretty: true
shipper 部分是一些和网络拓扑相关的配置,就目前来说,大多数是 packetbeat 独有的。
shipper:
name: "my-shipper"
tags: ["my-service", "hardware", "test"]
ignore_outgoing: true
refresh_topology_freq: 10
topology_expire: 15
geoip:
paths:
- "/usr/share/GeoIP/GeoLiteCity.dat"
runoptions:
uid=501