官网地址:https://www.elastic.co/guide/en/logstash-versioned-plugins/current/index.html
Logstash的基础架构类型为pipeline流水线,如下图所示:
INPUT:数据采集(常用插件:stdin、file、kafka、beat.http)
FILTER:数据解析/转换(常用插件:Grok正则捕获、Date时间处理、Json编解码、Mutate数据修改等)
OUTPUT:数据输出(常用插件:Elasticsearch)
Codec:编码插件,它可以作为对输入或输出运行该过滤。和其它产品结合,(常用:rubydebug、graphite、fluent、nmap)
1. INPUT输入插件
input插件用于指定输入源,一个pipeline 可以有多个input插件,我们主要围绕下面几个input进行介绍:
1.1 file(读取文件)
常用选项:
type #字符串类型,表明日志类型,相当于标记日志
path #要导入文件的位置
start_position #记录文本位置,有两个参数beginning、end
stat_interval #状态间隔时间,默认1s
示例:
input{
file{
path => ["/var/log/messages"]
type => "system"
start_position => "beginning"
stat_interval => 3
}
}
1.2 redis
常用选项:
data_type # redis插件工作方式,["list", "channel", "pattern_channel"]
key # 监听的键值
batch_count # EVAL命令返回的事件数目,设置为5表示一次请求返回5条日志信息
host # redis地址
port # redis端口
db # redis数据库的编号,默认为0
password #密码
threads #启动线程数
timeout #超时时间,默认5s
示例:
input {
redis {
batch_count => 1
data_type => "list" #list 类型,数据输入到 redis 服务器上暂存,logstash 则连上 redis 服务器取走
key => "logstash-test-list"
host => "127.0.0.1"
port => 6379
password => "123123"
db => 0
threads => 1
}
}
1.3 kafika
常用选项:
bootstrap_servers # 字符串类型,默认写法"localhost:9092"
client_id # 客户端id,默认logstash
group_id # 消费者分组,可以通过组 ID 去指定,默认logstash
auto_offset_reset # 位置偏移量,默认有四种:earliest最早、latest最新、none抛出异常、anything else抛出异常
consumer_threads # 使用线程数,默认为1
decorate_events #此属性会将当前topic、offset、group、partition等信息也带到message中,默认为false
topics #数组类型,可配置多个topic
topics_id #指定消费话题,也是必填项目,指定消费某个 topic
reset_beginning #logstash 启动后从什么位置开始读取数据,默认是结束位置
type #所有插件通用属性
示例:
input{
kafka{
bootstrap_servers => ["192.168.110.31:9092,192.168.110.31:9093,192.168.110.31:9094"]
client_id => "test"
group_id => "test"
auto_offset_reset => "latest" //从最新的偏移量开始消费
consumer_threads => 5
decorate_events => true //此属性会将当前topic、offset、group、partition等信息也带到message中
topics => ["logq","loge"] //数组类型,可配置多个topic
type =</